Skip to content

Commit 5bc815e

Browse files
committed
Modernize some Ix code.
1 parent 8778a4b commit 5bc815e

File tree

26 files changed

+78
-229
lines changed

26 files changed

+78
-229
lines changed

Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,33 +116,31 @@ private static IEnumerable<TSource> CatchCore<TSource>(IEnumerable<IEnumerable<T
116116

117117
foreach (var source in sources)
118118
{
119-
using (var e = source.GetEnumerator())
119+
using var e = source.GetEnumerator();
120+
error = null;
121+
122+
while (true)
120123
{
121-
error = null;
124+
var c = default(TSource);
122125

123-
while (true)
126+
try
124127
{
125-
var c = default(TSource);
126-
127-
try
128-
{
129-
if (!e.MoveNext())
130-
break;
131-
132-
c = e.Current;
133-
}
134-
catch (Exception ex)
135-
{
136-
error = ex;
128+
if (!e.MoveNext())
137129
break;
138-
}
139130

140-
yield return c;
131+
c = e.Current;
141132
}
142-
143-
if (error == null)
133+
catch (Exception ex)
134+
{
135+
error = ex;
144136
break;
137+
}
138+
139+
yield return c;
145140
}
141+
142+
if (error == null)
143+
break;
146144
}
147145

148146
if (error != null)

Ix.NET/Source/System.Interactive/System/Linq/Operators/Concat.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public static partial class EnumerableEx
1717
public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<IEnumerable<TSource>> sources)
1818
{
1919
if (sources == null)
20-
{
2120
throw new ArgumentNullException(nameof(sources));
22-
}
2321

2422
return ConcatCore(sources);
2523
}
@@ -33,9 +31,7 @@ public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<IEnumerable<
3331
public static IEnumerable<TSource> Concat<TSource>(params IEnumerable<TSource>[] sources)
3432
{
3533
if (sources == null)
36-
{
3734
throw new ArgumentNullException(nameof(sources));
38-
}
3935

4036
return ConcatCore(sources);
4137
}

Ix.NET/Source/System.Interactive/System/Linq/Operators/Create.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public static partial class EnumerableEx
1818
public static IEnumerable<TResult> Create<TResult>(Func<IEnumerator<TResult>> getEnumerator)
1919
{
2020
if (getEnumerator == null)
21-
{
2221
throw new ArgumentNullException(nameof(getEnumerator));
23-
}
2422

2523
return new AnonymousEnumerable<TResult>(getEnumerator);
2624
}
@@ -37,9 +35,7 @@ public static IEnumerable<TResult> Create<TResult>(Func<IEnumerator<TResult>> ge
3735
public static IEnumerable<T> Create<T>(Action<IYielder<T>> create)
3836
{
3937
if (create == null)
40-
{
4138
throw new ArgumentNullException(nameof(create));
42-
}
4339

4440
foreach (var x in new Yielder<T>(create))
4541
{
@@ -51,10 +47,7 @@ private sealed class AnonymousEnumerable<TResult> : IEnumerable<TResult>
5147
{
5248
private readonly Func<IEnumerator<TResult>> _getEnumerator;
5349

54-
public AnonymousEnumerable(Func<IEnumerator<TResult>> getEnumerator)
55-
{
56-
_getEnumerator = getEnumerator;
57-
}
50+
public AnonymousEnumerable(Func<IEnumerator<TResult>> getEnumerator) => _getEnumerator = getEnumerator;
5851

5952
public IEnumerator<TResult> GetEnumerator() => _getEnumerator();
6053

Ix.NET/Source/System.Interactive/System/Linq/Operators/Do.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,30 @@ public static IEnumerable<TSource> Do<TSource>(this IEnumerable<TSource> source,
108108

109109
private static IEnumerable<TSource> DoCore<TSource>(IEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
110110
{
111-
using (var e = source.GetEnumerator())
111+
using var e = source.GetEnumerator();
112+
113+
while (true)
112114
{
113-
while (true)
115+
TSource current;
116+
try
117+
{
118+
if (!e.MoveNext())
119+
break;
120+
121+
current = e.Current;
122+
}
123+
catch (Exception ex)
114124
{
115-
var current = default(TSource);
116-
try
117-
{
118-
if (!e.MoveNext())
119-
break;
120-
121-
current = e.Current;
122-
}
123-
catch (Exception ex)
124-
{
125-
onError(ex);
126-
throw;
127-
}
128-
129-
onNext(current);
130-
131-
yield return current;
125+
onError(ex);
126+
throw;
132127
}
133128

134-
onCompleted();
129+
onNext(current);
130+
131+
yield return current;
135132
}
133+
134+
onCompleted();
136135
}
137136
}
138137
}

Ix.NET/Source/System.Interactive/System/Linq/Operators/Expand.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ public static partial class EnumerableEx
1818
public static IEnumerable<TSource> Expand<TSource>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TSource>> selector)
1919
{
2020
if (source == null)
21-
{
2221
throw new ArgumentNullException(nameof(source));
23-
}
24-
2522
if (selector == null)
26-
{
2723
throw new ArgumentNullException(nameof(selector));
28-
}
2924

3025
return ExpandCore(source, selector);
3126
}

Ix.NET/Source/System.Interactive/System/Linq/Operators/Finally.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ public static partial class EnumerableEx
1818
public static IEnumerable<TSource> Finally<TSource>(this IEnumerable<TSource> source, Action finallyAction)
1919
{
2020
if (source == null)
21-
{
2221
throw new ArgumentNullException(nameof(source));
23-
}
24-
2522
if (finallyAction == null)
26-
{
2723
throw new ArgumentNullException(nameof(finallyAction));
28-
}
2924

3025
return FinallyCore(source, finallyAction);
3126
}

Ix.NET/Source/System.Interactive/System/Linq/Operators/For.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,11 @@ public static partial class EnumerableEx
2323
public static IEnumerable<TResult> For<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> resultSelector)
2424
{
2525
if (source == null)
26-
{
2726
throw new ArgumentNullException(nameof(source));
28-
}
29-
3027
if (resultSelector == null)
31-
{
3228
throw new ArgumentNullException(nameof(resultSelector));
33-
}
34-
35-
return ForCore(source, resultSelector).Concat();
36-
}
3729

38-
private static IEnumerable<IEnumerable<TResult>> ForCore<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> resultSelector)
39-
{
40-
return source.Select(resultSelector);
30+
return source.Select(resultSelector).Concat();
4131
}
4232
}
4333
}

Ix.NET/Source/System.Interactive/System/Linq/Operators/ForEach.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ public static partial class EnumerableEx
1717
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> onNext)
1818
{
1919
if (source == null)
20-
{
2120
throw new ArgumentNullException(nameof(source));
22-
}
23-
2421
if (onNext == null)
25-
{
2622
throw new ArgumentNullException(nameof(onNext));
27-
}
2823

2924
foreach (var item in source)
3025
{
@@ -41,14 +36,9 @@ public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSo
4136
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource, int> onNext)
4237
{
4338
if (source == null)
44-
{
4539
throw new ArgumentNullException(nameof(source));
46-
}
47-
4840
if (onNext == null)
49-
{
5041
throw new ArgumentNullException(nameof(onNext));
51-
}
5242

5343
var i = 0;
5444
foreach (var item in source)

Ix.NET/Source/System.Interactive/System/Linq/Operators/Generate.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,11 @@ public static partial class EnumerableEx
2121
public static IEnumerable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector)
2222
{
2323
if (condition == null)
24-
{
2524
throw new ArgumentNullException(nameof(condition));
26-
}
27-
2825
if (iterate == null)
29-
{
3026
throw new ArgumentNullException(nameof(iterate));
31-
}
32-
3327
if (resultSelector == null)
34-
{
3528
throw new ArgumentNullException(nameof(resultSelector));
36-
}
3729

3830
return GenerateCore(initialState, condition, iterate, resultSelector);
3931
}

Ix.NET/Source/System.Interactive/System/Linq/Operators/Hide.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ public static partial class EnumerableEx
2121
public static IEnumerable<TSource> Hide<TSource>(this IEnumerable<TSource> source)
2222
{
2323
if (source == null)
24-
{
2524
throw new ArgumentNullException(nameof(source));
26-
}
2725

2826
return HideCore(source);
2927
}

0 commit comments

Comments
 (0)