Skip to content

Commit 044ff7c

Browse files
authored
Resolve SDK 8.0.2xx diagnostics (#2100)
It looks like the 8.0.200 .NET SDK added a lot of new diagnostics suggesting the use of collection expressions. For the most part we have taken these suggestions, but in some cases we've retained the existing code so you can see what types are being used. I find that in methods with lots of overloads (e.g., Assert.AreEqual) it becomes quite difficult to work out what will actually happen if you replace an explicitly typed list initializer with just `[...]`.
1 parent 8da262d commit 044ff7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+466
-458
lines changed

Ix.NET/Integration/Android/Resources/Resource.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rx.NET/Integration/Installation/Android/Resources/Resource.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Description>Reactive Extensions (Rx) for .NET - Testing Library</Description>
1010
<PackageReadmeFile>readme.md</PackageReadmeFile>
1111
<!-- NB: A lot of CA and IDE warnings are disabled because of the .cs files included from xunit.assert.source. -->
12-
<NoWarn>$(NoWarn);IDE0054;IDE0066;CA1305;CA1307;CA1032;CA1064;CA1704;CA1822;CA1812;CA1820;CA1823;CA1825;CA1845;CA2249;IDE0016;IDE0018;IDE0019;IDE0020;IDE0031;IDE0039;IDE0044;IDE0059;IDE0074;IDE0270</NoWarn>
12+
<NoWarn>$(NoWarn);IDE0054;IDE0066;CA1305;CA1307;CA1032;CA1064;CA1704;CA1822;CA1812;CA1820;CA1823;CA1825;CA1845;CA2249;IDE0016;IDE0018;IDE0019;IDE0020;IDE0028;IDE0031;IDE0039;IDE0044;IDE0059;IDE0074;IDE0090;IDE0270;IDE0300</NoWarn>
1313
</PropertyGroup>
1414

1515
<PropertyGroup>

Rx.NET/Source/src/System.Reactive/Internal/Lookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public IEnumerable<E> this[K key]
3939
{
4040
if (!_dictionary.TryGetValue(key, out var list))
4141
{
42-
return Enumerable.Empty<E>();
42+
return [];
4343
}
4444

4545
return Hide(list);

Rx.NET/Source/src/System.Reactive/Linq/Observable/Buffer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal sealed class ExactSink : Sink<TSource, IList<TSource>>
2929
{
3030
private readonly int _count;
3131
private int _index;
32-
private IList<TSource>? _buffer;
32+
private List<TSource>? _buffer;
3333

3434
internal ExactSink(IObserver<IList<TSource>> observer, int count) : base(observer)
3535
{
@@ -41,7 +41,7 @@ public override void OnNext(TSource value)
4141
var buffer = _buffer;
4242
if (buffer == null)
4343
{
44-
buffer = new List<TSource>();
44+
buffer = [];
4545
_buffer = buffer;
4646
}
4747

@@ -102,7 +102,7 @@ internal sealed class SkipSink : Sink<TSource, IList<TSource>>
102102
private readonly int _count;
103103
private readonly int _skip;
104104
private int _index;
105-
private IList<TSource>? _buffer;
105+
private List<TSource>? _buffer;
106106

107107
internal SkipSink(IObserver<IList<TSource>> observer, int count, int skip) : base(observer)
108108
{
@@ -116,7 +116,7 @@ public override void OnNext(TSource value)
116116
var buffer = _buffer;
117117
if (idx == 0)
118118
{
119-
buffer = new List<TSource>();
119+
buffer = [];
120120
_buffer = buffer;
121121
}
122122

Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ public void Dispose()
135135

136136
private Action AddHandlerCore(Delegate handler)
137137
{
138-
_addMethod.Invoke(_target, new object[] { handler });
139-
return () => _removeMethod.Invoke(_target, new object[] { handler });
138+
_addMethod.Invoke(_target, [handler]);
139+
return () => _removeMethod.Invoke(_target, [handler]);
140140
}
141141

142142
private Action AddHandlerCoreWinRT(Delegate handler)
143143
{
144-
var token = _addMethod.Invoke(_target, new object[] { handler });
144+
var token = _addMethod.Invoke(_target, [handler]);
145145
return () => _removeMethod.Invoke(_target, [token]);
146146
}
147147
}

Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Blocking.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal partial class QueryLanguage
1616

1717
public virtual IEnumerable<IList<TSource>> Chunkify<TSource>(IObservable<TSource> source)
1818
{
19-
return source.Collect<TSource, IList<TSource>>(() => new List<TSource>(), (lst, x) => { lst.Add(x); return lst; }, _ => new List<TSource>());
19+
return source.Collect<TSource, IList<TSource>>(() => [], (lst, x) => { lst.Add(x); return lst; }, _ => []);
2020
}
2121

2222
#endregion

Rx.NET/Source/src/System.Reactive/ObservableQuery.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ private IList<Expression> VisitQbservableOperatorArguments(MethodInfo method, IE
322322
if (lastArgument.NodeType == ExpressionType.NewArrayInit)
323323
{
324324
var paramsArray = (NewArrayExpression)lastArgument;
325-
return new List<Expression>
326-
{
325+
return
326+
[
327327
Expression.NewArrayInit(
328328
typeof(Plan<>).MakeGenericType(method.GetGenericArguments()[0]),
329329
paramsArray.Expressions.Select(param => Visit(param))
330330
)
331-
};
331+
];
332332
}
333333
}
334334

Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class AsyncSubject<T> : SubjectBase<T>, INotifyCompletion
2222
private bool _hasValue;
2323
private Exception? _exception;
2424

25-
#pragma warning disable CA1825 // (Avoid zero-length array allocations.) The identity of these arrays matters, so we can't use the shared Array.Empty<T>() instance
25+
#pragma warning disable CA1825,IDE0300 // (Avoid zero-length array allocations. Use collection expressions) The identity of these arrays matters, so we can't use the shared Array.Empty<T>() instance either explicitly, or indirectly via a collection expression
2626
/// <summary>
2727
/// A pre-allocated empty array indicating the AsyncSubject has terminated.
2828
/// </summary>
@@ -31,7 +31,7 @@ public sealed class AsyncSubject<T> : SubjectBase<T>, INotifyCompletion
3131
/// A pre-allocated empty array indicating the AsyncSubject has been disposed.
3232
/// </summary>
3333
private static readonly AsyncSubjectDisposable[] Disposed = new AsyncSubjectDisposable[0];
34-
#pragma warning restore CA1825
34+
#pragma warning restore CA1825,IDE0300
3535

3636
#endregion
3737

Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public sealed class Subject<T> : SubjectBase<T>
1818

1919
private SubjectDisposable[] _observers;
2020
private Exception? _exception;
21-
#pragma warning disable CA1825 // (Avoid zero-length array allocations.) The identity of these arrays matters, so we can't use the shared Array.Empty<T>() instance
21+
#pragma warning disable CA1825,IDE0300 // (Avoid zero-length array allocations. Use collection expressions) The identity of these arrays matters, so we can't use the shared Array.Empty<T>() instance either explicitly, or indirectly via a collection expression
2222
private static readonly SubjectDisposable[] Terminated = new SubjectDisposable[0];
2323
private static readonly SubjectDisposable[] Disposed = new SubjectDisposable[0];
24-
#pragma warning restore CA1825
24+
#pragma warning restore CA1825,IDE0300
2525

2626
#endregion
2727

0 commit comments

Comments
 (0)