Преглед на файлове

Another batch of nullable enables.

Bart De Smet преди 5 години
родител
ревизия
bfff23243e

+ 0 - 2
Rx.NET/Source/src/System.Reactive/AnonymousSafeObserver.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Threading;
 
 namespace System.Reactive

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs

@@ -33,7 +33,7 @@ namespace System.Reactive.Concurrency
         {
             Debug.Assert(t.IsFaulted && t.Exception != null);
 
-            if (t.Exception.InnerException != null)
+            if (t.Exception!.InnerException != null)
             {
                 return t.Exception.InnerException;
             }

+ 4 - 6
Rx.NET/Source/src/System.Reactive/EventPattern.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 
 namespace System.Reactive
@@ -58,7 +56,7 @@ namespace System.Reactive
         /// </summary>
         /// <param name="other">An object to compare to the current <see cref="EventPattern{TSender, TEventArgs}"/> object.</param>
         /// <returns><c>true</c> if both <see cref="EventPattern{TSender, TEventArgs}"/> objects represent the same event; otherwise, <c>false</c>.</returns>
-        public bool Equals(EventPattern<TSender, TEventArgs> other)
+        public bool Equals(EventPattern<TSender, TEventArgs>? other)
         {
             if (other is null)
             {
@@ -78,7 +76,7 @@ namespace System.Reactive
         /// </summary>
         /// <param name="obj">The System.Object to compare with the current <see cref="EventPattern{TSender, TEventArgs}"/>.</param>
         /// <returns><c>true</c> if the specified System.Object is equal to the current <see cref="EventPattern{TSender, TEventArgs}"/>; otherwise, <c>false</c>.</returns>
-        public override bool Equals(object obj) => Equals(obj as EventPattern<TSender, TEventArgs>);
+        public override bool Equals(object? obj) => Equals(obj as EventPattern<TSender, TEventArgs>);
 
         /// <summary>
         /// Returns the hash code for the current <see cref="EventPattern{TSender, TEventArgs}"/> instance.
@@ -86,8 +84,8 @@ namespace System.Reactive
         /// <returns>A hash code for the current <see cref="EventPattern{TSender, TEventArgs}"/> instance.</returns>
         public override int GetHashCode()
         {
-            var x = EqualityComparer<TSender>.Default.GetHashCode(Sender);
-            var y = EqualityComparer<TEventArgs>.Default.GetHashCode(EventArgs);
+            var x = Sender?.GetHashCode() ?? 0;
+            var y = EventArgs?.GetHashCode() ?? 0;
             return (x << 5) + (x ^ y);
         }
 

+ 0 - 2
Rx.NET/Source/src/System.Reactive/EventPatternSource.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive
 {
     internal sealed class EventPatternSource<TEventArgs> : EventPatternSourceBase<object, TEventArgs>, IEventPatternSource<TEventArgs>

+ 1 - 3
Rx.NET/Source/src/System.Reactive/EventPatternSourceBase.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 
 namespace System.Reactive
@@ -144,7 +142,7 @@ namespace System.Reactive
                 throw new ArgumentNullException(nameof(handler));
             }
 
-            IDisposable d = null;
+            IDisposable? d = null;
 
             lock (_subscriptions)
             {

+ 1 - 3
Rx.NET/Source/src/System.Reactive/EventSource.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 
 namespace System.Reactive
@@ -84,7 +82,7 @@ namespace System.Reactive
 
         private void Remove(Delegate handler)
         {
-            IDisposable d = null;
+            IDisposable? d = null;
 
             lock (_subscriptions)
             {

+ 0 - 2
Rx.NET/Source/src/System.Reactive/ListObservable.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections;
 using System.Collections.Generic;
 using System.Reactive.Disposables;

+ 10 - 12
Rx.NET/Source/src/System.Reactive/Notification.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
@@ -65,7 +63,7 @@ namespace System.Reactive
         /// <summary>
         /// Returns the exception of an OnError notification or returns <c>null</c>.
         /// </summary>
-        public abstract Exception Exception { get; }
+        public abstract Exception? Exception { get; }
 
         /// <summary>
         /// Gets the kind of notification that is represented.
@@ -97,7 +95,7 @@ namespace System.Reactive
             /// <summary>
             /// Returns <c>null</c>.
             /// </summary>
-            public override Exception Exception => null;
+            public override Exception? Exception => null;
 
             /// <summary>
             /// Returns <c>true</c>.
@@ -112,12 +110,12 @@ namespace System.Reactive
             /// <summary>
             /// Returns the hash code for this instance.
             /// </summary>
-            public override int GetHashCode() => EqualityComparer<T>.Default.GetHashCode(Value);
+            public override int GetHashCode() => Value?.GetHashCode() ?? 0;
 
             /// <summary>
             /// Indicates whether this instance and a specified object are equal.
             /// </summary>
-            public override bool Equals(Notification<T> other)
+            public override bool Equals(Notification<T>? other)
             {
                 if (ReferenceEquals(this, other))
                 {
@@ -245,7 +243,7 @@ namespace System.Reactive
             /// <summary>
             /// Throws the exception.
             /// </summary>
-            public override T Value { get { Exception.Throw(); return default; } }
+            public override T Value { get { Exception.Throw(); return default!; } }
 
             /// <summary>
             /// Returns the exception.
@@ -270,7 +268,7 @@ namespace System.Reactive
             /// <summary>
             /// Indicates whether this instance and other are equal.
             /// </summary>
-            public override bool Equals(Notification<T> other)
+            public override bool Equals(Notification<T>? other)
             {
                 if (ReferenceEquals(this, other))
                 {
@@ -408,7 +406,7 @@ namespace System.Reactive
             /// <summary>
             /// Returns <c>null</c>.
             /// </summary>
-            public override Exception Exception => null;
+            public override Exception? Exception => null;
 
             /// <summary>
             /// Returns <c>false</c>.
@@ -428,7 +426,7 @@ namespace System.Reactive
             /// <summary>
             /// Indicates whether this instance and other are equal.
             /// </summary>
-            public override bool Equals(Notification<T> other)
+            public override bool Equals(Notification<T>? other)
             {
                 if (ReferenceEquals(this, other))
                 {
@@ -541,7 +539,7 @@ namespace System.Reactive
         /// This means two <see cref="Notification{T}"/> objects can be equal even though they don't represent the same observer method call, but have the same Kind and have equal parameters passed to the observer method.
         /// In case one wants to determine whether two <see cref="Notification{T}"/> objects represent the same observer method call, use Object.ReferenceEquals identity equality instead.
         /// </remarks>
-        public abstract bool Equals(Notification<T> other);
+        public abstract bool Equals(Notification<T>? other);
 
         /// <summary>
         /// Determines whether the two specified <see cref="Notification{T}"/> objects have the same observer message payload.
@@ -592,7 +590,7 @@ namespace System.Reactive
         /// This means two <see cref="Notification{T}"/> objects can be equal even though they don't represent the same observer method call, but have the same Kind and have equal parameters passed to the observer method.
         /// In case one wants to determine whether two <see cref="Notification{T}"/> objects represent the same observer method call, use Object.ReferenceEquals identity equality instead.
         /// </remarks>
-        public override bool Equals(object obj) => Equals(obj as Notification<T>);
+        public override bool Equals(object? obj) => Equals(obj as Notification<T>);
 
         /// <summary>
         /// Invokes the observer's method corresponding to the notification.

+ 1 - 3
Rx.NET/Source/src/System.Reactive/Observable.Extensions.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.ComponentModel;
 using System.Reactive;
 using System.Reactive.Disposables;
@@ -341,7 +339,7 @@ namespace System
                     //
                     var d = source.Subscribe/*Unsafe*/(consumer);
 
-                    consumer.SetResource(token.Register(state => ((IDisposable)state).Dispose(), d));
+                    consumer.SetResource(token.Register(state => ((IDisposable)state!).Dispose(), d));
                 }
             }
             else

+ 21 - 19
Rx.NET/Source/src/System.Reactive/ObservableQuery.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
@@ -60,7 +58,7 @@ namespace System.Reactive
                 Expression.Call(
                     AsQueryable.MakeGenericMethod(typeof(TElement)),
                     Expression.Call(
-                        typeof(Observable).GetMethod(nameof(Observable.ToEnumerable)).MakeGenericMethod(typeof(TElement)),
+                        typeof(Observable).GetMethod(nameof(Observable.ToEnumerable))!.MakeGenericMethod(typeof(TElement)),
                         arg0
                     )
                 );
@@ -73,7 +71,7 @@ namespace System.Reactive
             return Expression.Lambda<Func<IQueryable<TElement>>>(res).Compile()();
         }
 
-        private static MethodInfo _staticAsQueryable;
+        private static MethodInfo? _staticAsQueryable;
 
         private static MethodInfo AsQueryable
         {
@@ -106,31 +104,35 @@ namespace System.Reactive
 
     internal class ObservableQuery
     {
-        protected object _source;
+        protected object? _source;
         protected Expression _expression;
 
-        public object Source
+        public ObservableQuery(object source)
         {
-            get { return _source; }
+            _source = source;
+            _expression = Expression.Constant(this);
         }
 
-        public Expression Expression
+        public ObservableQuery(Expression expression)
         {
-            get { return _expression; }
+            _expression = expression;
         }
+
+        public object? Source => _source;
+
+        public Expression Expression => _expression;
     }
 
     internal class ObservableQuery<TSource> : ObservableQuery, IQbservable<TSource>
     {
         internal ObservableQuery(IObservable<TSource> source)
+            : base(source)
         {
-            _source = source;
-            _expression = Expression.Constant(this);
         }
 
         internal ObservableQuery(Expression expression)
+            : base(expression)
         {
-            _expression = expression;
         }
 
         public Type ElementType => typeof(TSource);
@@ -153,7 +155,7 @@ namespace System.Reactive
             return ((IObservable<TSource>)_source).Subscribe/*Unsafe*/(observer);
         }
 
-        public override string ToString()
+        public override string? ToString()
         {
             if (_expression is ConstantExpression c && c.Value == this)
             {
@@ -191,9 +193,9 @@ namespace System.Reactive
                 var method = node.Method;
                 var declaringType = method.DeclaringType;
 #if (CRIPPLED_REFLECTION && HAS_WINRT)
-                var baseType = declaringType.GetTypeInfo().BaseType;
+                var baseType = declaringType?.GetTypeInfo().BaseType;
 #else
-                var baseType = declaringType.BaseType;
+                var baseType = declaringType?.BaseType;
 #endif
                 if (baseType == typeof(QueryablePattern))
                 {
@@ -336,7 +338,7 @@ namespace System.Reactive
             private class Lazy<T>
             {
                 private readonly Func<T> _factory;
-                private T _value;
+                private T? _value;
                 private bool _initialized;
 
                 public Lazy(Func<T> factory)
@@ -357,7 +359,7 @@ namespace System.Reactive
                             }
                         }
 
-                        return _value;
+                        return _value!;
                     }
                 }
             }
@@ -380,7 +382,7 @@ namespace System.Reactive
                 }
                 else
                 {
-                    targetType = method.DeclaringType;
+                    targetType = method.DeclaringType!; // NB: These methods were found from a declaring type.
 
 #if (CRIPPLED_REFLECTION && HAS_WINRT)
                     var typeInfo = targetType.GetTypeInfo();
@@ -442,7 +444,7 @@ namespace System.Reactive
 #endif
             }
 
-            private static bool ArgsMatch(MethodInfo method, IList<Expression> arguments, Type[] typeArgs)
+            private static bool ArgsMatch(MethodInfo method, IList<Expression> arguments, Type[]? typeArgs)
             {
                 //
                 // Number of parameters should match. Notice we've sanitized IQbservableProvider "this"

+ 7 - 9
Rx.NET/Source/src/System.Reactive/Runtime/CompilerServices/TaskObservableMethodBuilder.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive;
 using System.Reactive.Concurrency;
 using System.Reactive.Disposables;
@@ -213,17 +211,17 @@ namespace System.Runtime.CompilerServices
             /// The underlying observable sequence to subscribe to in case the asynchronous method did not
             /// finish synchronously.
             /// </summary>
-            private readonly AsyncSubject<T> _subject;
+            private readonly AsyncSubject<T>? _subject;
 
             /// <summary>
             /// The result returned by the asynchronous method in case the method finished synchronously.
             /// </summary>
-            private readonly T _result;
+            private readonly T? _result;
 
             /// <summary>
             /// The exception thrown by the asynchronous method in case the method finished synchronously.
             /// </summary>
-            private readonly Exception _exception;
+            private readonly Exception? _exception;
 
             /// <summary>
             /// Creates a new <see cref="TaskObservable"/> for an asynchronous method that has not finished yet.
@@ -265,7 +263,7 @@ namespace System.Runtime.CompilerServices
                     throw new InvalidOperationException();
                 }
 
-                _subject.OnNext(result);
+                _subject!.OnNext(result);
                 _subject.OnCompleted();
             }
 
@@ -282,7 +280,7 @@ namespace System.Runtime.CompilerServices
                     throw new InvalidOperationException();
                 }
 
-                _subject.OnError(exception);
+                _subject!.OnError(exception);
             }
 
             /// <summary>
@@ -304,7 +302,7 @@ namespace System.Runtime.CompilerServices
                     return Disposable.Empty;
                 }
 
-                observer.OnNext(_result);
+                observer.OnNext(_result!);
                 return Disposable.Empty;
             }
 
@@ -332,7 +330,7 @@ namespace System.Runtime.CompilerServices
 
                 _exception.ThrowIfNotNull();
 
-                return _result;
+                return _result!;
             }
 
             /// <summary>

+ 0 - 2
Rx.NET/Source/src/System.Reactive/TaskObservable.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Runtime.CompilerServices;
 
 namespace System.Reactive

+ 1 - 3
Rx.NET/Source/src/System.Reactive/TimeInterval.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 using System.Globalization;
 
@@ -68,7 +66,7 @@ namespace System.Reactive
         /// </summary>
         /// <param name="obj">The System.Object to compare with the current <see cref="TimeInterval{T}"/>.</param>
         /// <returns><c>true</c> if the specified System.Object is equal to the current <see cref="TimeInterval{T}"/>; otherwise, <c>false</c>.</returns>
-        public override bool Equals(object obj) => obj is TimeInterval<T> && Equals((TimeInterval<T>)obj);
+        public override bool Equals(object? obj) => obj is TimeInterval<T> && Equals((TimeInterval<T>)obj);
 
         /// <summary>
         /// Returns the hash code for the current <see cref="TimeInterval{T}"/> value.

+ 1 - 3
Rx.NET/Source/src/System.Reactive/Timestamped.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 using System.Globalization;
 
@@ -69,7 +67,7 @@ namespace System.Reactive
         /// </summary>
         /// <param name="obj">The System.Object to compare with the current <see cref="Timestamped{T}" />.</param>
         /// <returns><c>true</c> if the specified System.Object is equal to the current <see cref="Timestamped{T}" />; otherwise, <c>false</c>.</returns>
-        public override bool Equals(object obj) => obj is Timestamped<T> && Equals((Timestamped<T>)obj);
+        public override bool Equals(object? obj) => obj is Timestamped<T> && Equals((Timestamped<T>)obj);
 
         /// <summary>
         /// Returns the hash code for the current <see cref="Timestamped{T}" /> value.

+ 1 - 3
Rx.NET/Source/src/System.Reactive/Unit.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive
 {
     /// <summary>
@@ -26,7 +24,7 @@ namespace System.Reactive
         /// </summary>
         /// <param name="obj">The System.Object to compare with the current <see cref="Unit"/>.</param>
         /// <returns><c>true</c> if the specified System.Object is a <see cref="Unit"/> value; otherwise, <c>false</c>.</returns>
-        public override bool Equals(object obj) => obj is Unit;
+        public override bool Equals(object? obj) => obj is Unit;
 
         /// <summary>
         /// Returns the hash code for the current <see cref="Unit"/> value.

+ 8 - 8
Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.verified.cs

@@ -54,8 +54,8 @@ namespace System.Reactive
         public EventPattern(TSender sender, TEventArgs e) { }
         public TEventArgs EventArgs { get; }
         public TSender Sender { get; }
-        public override bool Equals(object obj) { }
-        public bool Equals(System.Reactive.EventPattern<TSender, TEventArgs> other) { }
+        public bool Equals(System.Reactive.EventPattern<TSender, TEventArgs>? other) { }
+        public override bool Equals(object? obj) { }
         public override int GetHashCode() { }
         public static bool operator !=(System.Reactive.EventPattern<TSender, TEventArgs> first, System.Reactive.EventPattern<TSender, TEventArgs> second) { }
         public static bool operator ==(System.Reactive.EventPattern<TSender, TEventArgs> first, System.Reactive.EventPattern<TSender, TEventArgs> second) { }
@@ -130,7 +130,7 @@ namespace System.Reactive
     public abstract class Notification<T> : System.IEquatable<System.Reactive.Notification<T>>
     {
         protected Notification() { }
-        public abstract System.Exception Exception { get; }
+        public abstract System.Exception? Exception { get; }
         public abstract bool HasValue { get; }
         public abstract System.Reactive.NotificationKind Kind { get; }
         public abstract T Value { get; }
@@ -138,8 +138,8 @@ namespace System.Reactive
         public abstract void Accept(System.Action<T> onNext, System.Action<System.Exception> onError, System.Action onCompleted);
         public abstract TResult Accept<TResult>(System.Reactive.IObserver<T, TResult> observer);
         public abstract TResult Accept<TResult>(System.Func<T, TResult> onNext, System.Func<System.Exception, TResult> onError, System.Func<TResult> onCompleted);
-        public override bool Equals(object obj) { }
-        public abstract bool Equals(System.Reactive.Notification<T> other);
+        public abstract bool Equals(System.Reactive.Notification<T>? other);
+        public override bool Equals(object? obj) { }
         public System.IObservable<T> ToObservable() { }
         public System.IObservable<T> ToObservable(System.Reactive.Concurrency.IScheduler scheduler) { }
         public static bool operator !=(System.Reactive.Notification<T> left, System.Reactive.Notification<T> right) { }
@@ -189,8 +189,8 @@ namespace System.Reactive
         public TimeInterval(T value, System.TimeSpan interval) { }
         public System.TimeSpan Interval { get; }
         public T Value { get; }
-        public override bool Equals(object obj) { }
         public bool Equals(System.Reactive.TimeInterval<T> other) { }
+        public override bool Equals(object? obj) { }
         public override int GetHashCode() { }
         public override string ToString() { }
         public static bool operator !=(System.Reactive.TimeInterval<T> first, System.Reactive.TimeInterval<T> second) { }
@@ -206,8 +206,8 @@ namespace System.Reactive
         public Timestamped(T value, System.DateTimeOffset timestamp) { }
         public System.DateTimeOffset Timestamp { get; }
         public T Value { get; }
-        public override bool Equals(object obj) { }
         public bool Equals(System.Reactive.Timestamped<T> other) { }
+        public override bool Equals(object? obj) { }
         public override int GetHashCode() { }
         public override string ToString() { }
         public static bool operator !=(System.Reactive.Timestamped<T> first, System.Reactive.Timestamped<T> second) { }
@@ -217,8 +217,8 @@ namespace System.Reactive
     public readonly struct Unit : System.IEquatable<System.Reactive.Unit>
     {
         public static System.Reactive.Unit Default { get; }
-        public override bool Equals(object obj) { }
         public bool Equals(System.Reactive.Unit other) { }
+        public override bool Equals(object? obj) { }
         public override int GetHashCode() { }
         public override string ToString() { }
         public static bool operator !=(System.Reactive.Unit first, System.Reactive.Unit second) { }