Browse Source

Fix a number of warnings.

Bart De Smet 5 years ago
parent
commit
adae5cfb30

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

@@ -70,7 +70,7 @@ namespace System.Reactive.Concurrency
         {
             if (scheduler is IServiceProvider svc)
             {
-                return (T)svc.GetService(typeof(T));
+                return (T?)svc.GetService(typeof(T));
             }
 
             return null;

+ 10 - 10
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs

@@ -34,7 +34,7 @@ namespace System.Reactive.Concurrency
             // the anonymous lambda can be replaced by the method group again. Until then,
             // to avoid the repetition of code, the call to Invoke is left intact.
             // Watch https://github.com/dotnet/roslyn/issues/5835
-            return scheduler.Schedule(action, static (s, a) => Invoke(s, a));
+            return scheduler.Schedule(action, static (_, a) => Invoke(a));
         }
 
         /// <summary>
@@ -109,7 +109,7 @@ namespace System.Reactive.Concurrency
             }
 
             // See note above.
-            return scheduler.Schedule(action, dueTime, static (s, a) => Invoke(s, a));
+            return scheduler.Schedule(action, dueTime, static (_, a) => Invoke(a));
         }
 
         /// <summary>
@@ -134,7 +134,7 @@ namespace System.Reactive.Concurrency
             }
 
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
         }
 
         /// <summary>
@@ -154,7 +154,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
 
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
         }
 
         /// <summary>
@@ -178,7 +178,7 @@ namespace System.Reactive.Concurrency
             }
 
             // See note above.
-            return scheduler.Schedule(action, dueTime, static (s, a) => Invoke(s, a));
+            return scheduler.Schedule(action, dueTime, static (_, a) => Invoke(a));
         }
 
         /// <summary>
@@ -203,7 +203,7 @@ namespace System.Reactive.Concurrency
             }
 
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
         }
 
         /// <summary>
@@ -223,7 +223,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
 
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
         }
 
         /// <summary>
@@ -248,19 +248,19 @@ namespace System.Reactive.Concurrency
             return scheduler.ScheduleLongRunning(action, static (a, c) => a(c));
         }
 
-        private static IDisposable Invoke(IScheduler scheduler, Action action)
+        private static IDisposable Invoke(Action action)
         {
             action();
             return Disposable.Empty;
         }
 
-        private static IDisposable Invoke<TState>(IScheduler scheduler, (TState state, Action<TState> action) tuple)
+        private static IDisposable Invoke<TState>((TState state, Action<TState> action) tuple)
         {
             tuple.action(tuple.state);
             return Disposable.Empty;
         }
 
-        private static IDisposable Invoke<TState>(IScheduler scheduler, (TState state, Func<TState, IDisposable> action) tuple)
+        private static IDisposable Invoke<TState>((TState state, Func<TState, IDisposable> action) tuple)
         {
             return tuple.action(tuple.state);
         }

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.ObserveOn.cs

@@ -112,17 +112,17 @@ namespace System.Reactive.Concurrency
                     _context.Post(OnCompletedPosted, state: null);
                 }
 
-                private void OnNextPosted(object value)
+                private void OnNextPosted(object? value)
                 {
-                    ForwardOnNext((TSource)value);
+                    ForwardOnNext((TSource)value!);
                 }
 
-                private void OnErrorPosted(object error)
+                private void OnErrorPosted(object? error)
                 {
-                    ForwardOnError((Exception)error);
+                    ForwardOnError((Exception)error!);
                 }
 
-                private void OnCompletedPosted(object ignored)
+                private void OnCompletedPosted(object? ignored)
                 {
                     ForwardOnCompleted();
                 }

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs

@@ -38,7 +38,7 @@ namespace System.Reactive.Concurrency
             // an anonymous delegate will allow delegate caching.
             // Watch https://github.com/dotnet/roslyn/issues/5835 for compiler
             // support for caching delegates from method groups.
-            return scheduler.ScheduleRelative(action, dueTime, static (s, a) => Invoke(s, a));
+            return scheduler.ScheduleRelative(action, dueTime, static (_, a) => Invoke(a));
         }
 
         /// <summary>
@@ -64,10 +64,10 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
             }
 
-            return scheduler.ScheduleAbsolute(action, dueTime, static (s, a) => Invoke(s, a));
+            return scheduler.ScheduleAbsolute(action, dueTime, static (_, a) => Invoke(a));
         }
 
-        private static IDisposable Invoke(IScheduler scheduler, Action action)
+        private static IDisposable Invoke(Action action)
         {
             action();
             return Disposable.Empty;

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Internal/HostLifecycleNotifications.Windows.cs

@@ -10,8 +10,8 @@ namespace System.Reactive.PlatformServices
 {
     internal class HostLifecycleNotifications : IHostLifecycleNotifications
     {
-        private EventHandler<SuspendingEventArgs> _suspending;
-        private EventHandler<object> _resuming;
+        private EventHandler<SuspendingEventArgs>? _suspending;
+        private EventHandler<object>? _resuming;
 
         public event EventHandler<HostSuspendingEventArgs> Suspending
         {

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs

@@ -436,7 +436,7 @@ namespace System.Reactive
         /// _queue field is not re-read from memory unnecessarily
         /// due to the memory barriers inside TryDequeue mandating it
         /// despite the field is read-only.</param>
-        private void Clear(ConcurrentQueue<T> q)
+        private static void Clear(ConcurrentQueue<T> q)
         {
             while (q.TryDequeue(out var _))
             {

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEvent.cs

@@ -178,7 +178,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
             if (_conversion == null)
             {
-                handler = ReflectionUtils.CreateDelegate<TDelegate>(onNext, typeof(Action<TEventArgs>).GetMethod(nameof(Action<TEventArgs>.Invoke)));
+                handler = ReflectionUtils.CreateDelegate<TDelegate>(onNext, typeof(Action<TEventArgs>).GetMethod(nameof(Action<TEventArgs>.Invoke))!);
             }
             else
             {

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

@@ -37,7 +37,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 if (_conversion == null)
                 {
                     Action<object, TEventArgs> h = (sender, eventArgs) => onNext(new EventPattern<TEventArgs>(sender, eventArgs));
-                    handler = ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<object, TEventArgs>).GetMethod(nameof(Action<object, TEventArgs>.Invoke)));
+                    handler = ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<object, TEventArgs>).GetMethod(nameof(Action<object, TEventArgs>.Invoke))!);
                 }
                 else
                 {
@@ -58,7 +58,7 @@ namespace System.Reactive.Linq.ObservableImpl
             protected override TDelegate GetHandler(Action<EventPattern<TSender, TEventArgs>> onNext)
             {
                 Action<TSender, TEventArgs> h = (sender, eventArgs) => onNext(new EventPattern<TSender, TEventArgs>(sender, eventArgs));
-                return ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke)));
+                return ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke))!);
             }
         }
 
@@ -91,7 +91,7 @@ namespace System.Reactive.Linq.ObservableImpl
             protected override Delegate GetHandler(Action<TResult> onNext)
             {
                 Action<TSender, TEventArgs> h = (sender, eventArgs) => onNext(_getResult(sender, eventArgs));
-                return ReflectionUtils.CreateDelegate(_delegateType, h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke)));
+                return ReflectionUtils.CreateDelegate(_delegateType, h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke))!);
             }
 
             protected override IDisposable AddHandler(Delegate handler)

+ 7 - 6
Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs

@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
+using System.Reactive.Concurrency;
 using System.Reactive.Disposables;
 using System.Threading;
 using System.Threading.Tasks;
@@ -629,7 +630,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         {
                             lock (_gate)
                             {
-                                ForwardOnError(task.Exception.InnerException);
+                                ForwardOnError(TaskHelpers.GetSingleException(task));
                             }
 
                             break;
@@ -786,7 +787,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         {
                             lock (_gate)
                             {
-                                ForwardOnError(task.Exception.InnerException);
+                                ForwardOnError(TaskHelpers.GetSingleException(task));
                             }
 
                             break;
@@ -1532,7 +1533,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     else
                     {
-                        task.ContinueWith((closureTask, thisObject) => ((_)thisObject).OnCompletedTask(closureTask), this, _cts.Token);
+                        task.ContinueWith((closureTask, thisObject) => ((_)thisObject!).OnCompletedTask(closureTask), this, _cts.Token);
                     }
                 }
 
@@ -1555,7 +1556,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         {
                             lock (_gate)
                             {
-                                ForwardOnError(task.Exception.InnerException);
+                                ForwardOnError(TaskHelpers.GetSingleException(task));
                             }
 
                             break;
@@ -1667,7 +1668,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     else
                     {
-                        task.ContinueWith((closureTask, thisObject) => ((_)thisObject).OnCompletedTask(closureTask), this, _cts.Token);
+                        task.ContinueWith((closureTask, thisObject) => ((_)thisObject!).OnCompletedTask(closureTask), this, _cts.Token);
                     }
                 }
 
@@ -1690,7 +1691,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         {
                             lock (_gate)
                             {
-                                ForwardOnError(task.Exception.InnerException);
+                                ForwardOnError(TaskHelpers.GetSingleException(task));
                             }
 
                             break;

+ 4 - 4
Rx.NET/Source/src/System.Reactive/Linq/Qbservable.Joins.cs

@@ -45,7 +45,7 @@ namespace System.Reactive.Linq
 #if CRIPPLED_REFLECTION
                     InfoOf(() => And<TLeft, TRight>(default, default)),
 #else
-                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TLeft), typeof(TRight)),
+                    ((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TLeft), typeof(TRight)),
 #endif
                     left.Expression,
                     GetSourceExpression(right)
@@ -80,7 +80,7 @@ namespace System.Reactive.Linq
 #if CRIPPLED_REFLECTION
                     InfoOf(() => Then<TSource, TResult>(default, default)),
 #else
-                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
+                    ((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TSource), typeof(TResult)),
 #endif
                     source.Expression,
                     selector
@@ -114,7 +114,7 @@ namespace System.Reactive.Linq
 #if CRIPPLED_REFLECTION
                     InfoOf(() => When<TResult>(default, default)),
 #else
-                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
+                    ((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TResult)),
 #endif
                     Expression.Constant(provider, typeof(IQbservableProvider)),
                     Expression.NewArrayInit(
@@ -151,7 +151,7 @@ namespace System.Reactive.Linq
 #if CRIPPLED_REFLECTION
                     InfoOf(() => When(default, default(IEnumerable<QueryablePlan<TResult>>))),
 #else
-                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
+                    ((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TResult)),
 #endif
                     Expression.Constant(provider, typeof(IQbservableProvider)),
                     Expression.Constant(plans, typeof(IEnumerable<QueryablePlan<TResult>>))

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Linq/Qbservable.cs

@@ -56,7 +56,7 @@ namespace System.Reactive.Linq
 #if CRIPPLED_REFLECTION
                     InfoOf(() => ToQbservable<TSource>(default)),
 #else
-                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
+                    ((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TSource)),
 #endif
                     source.Expression
                 )
@@ -90,7 +90,7 @@ namespace System.Reactive.Linq
 #if CRIPPLED_REFLECTION
                     InfoOf(() => ToQbservable<TSource>(default)),
 #else
-                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
+                    ((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TSource)),
 #endif
                     source.Expression,
                     Expression.Constant(scheduler)

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.NAry.cs

@@ -2,7 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-// This code was generated by a T4 template at 10/05/2020 14:10:15.
+// This code was generated by a T4 template at 10/05/2020 15:28:51.
 
 using System.Linq.Expressions;
 #if !CRIPPLED_REFLECTION

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Multiple.cs

@@ -142,7 +142,7 @@ namespace System.Reactive.Linq
             return Concat_(Select(sources, TaskObservableExtensions.ToObservable));
         }
 
-        private IObservable<TSource> Concat_<TSource>(IObservable<IObservable<TSource>> sources)
+        private static IObservable<TSource> Concat_<TSource>(IObservable<IObservable<TSource>> sources)
         {
             return new ConcatMany<TSource>(sources);
         }
@@ -263,7 +263,7 @@ namespace System.Reactive.Linq
             return Switch_(Select(sources, TaskObservableExtensions.ToObservable));
         }
 
-        private IObservable<TSource> Switch_<TSource>(IObservable<IObservable<TSource>> sources)
+        private static IObservable<TSource> Switch_<TSource>(IObservable<IObservable<TSource>> sources)
         {
             return new Switch<TSource>(sources);
         }

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

@@ -207,7 +207,7 @@ namespace System.Reactive
                         //
                         var pattern = Visit(node.Object);
                         var arguments = node.Arguments.Select(arg => Unquote(Visit(arg))).ToArray();
-                        var then = Expression.Call(pattern, "Then", method.GetGenericArguments(), arguments);
+                        var then = Expression.Call(pattern!, method.Name, method.GetGenericArguments(), arguments);
                         return then;
                     }
 
@@ -218,7 +218,7 @@ namespace System.Reactive
                         //
                         var lhs = Visit(node.Object);
                         var arguments = node.Arguments.Select(arg => Visit(arg)).ToArray();
-                        var and = Expression.Call(lhs, "And", method.GetGenericArguments(), arguments);
+                        var and = Expression.Call(lhs!, method.Name, method.GetGenericArguments(), arguments);
                         return and;
                     }
                 }

+ 2 - 1
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Concurrency/CoreDispatcherScheduler.cs

@@ -11,13 +11,14 @@ using Windows.UI.Core;
 #if HAS_OS_XAML
 using Windows.UI.Xaml;
 #endif
+
 namespace System.Reactive.Concurrency
 {
     /// <summary>
     /// Represents an object that schedules units of work on a <see cref="CoreDispatcher"/>.
     /// </summary>
     /// <remarks>
-    /// This scheduler type is typically used indirectly through the <see cref="Linq.DispatcherObservable.ObserveOnDispatcher{TSource}(IObservable{TSource})"/> and <see cref="Linq.DispatcherObservable.SubscribeOnDispatcher{TSource}(IObservable{TSource})"/> methods that use the current Dispatcher.
+    /// This scheduler type is typically used indirectly through the <see cref="Linq.CoreDispatcherObservable.ObserveOnCoreDispatcher{TSource}(IObservable{TSource})"/> and <see cref="Linq.CoreDispatcherObservable.SubscribeOnCoreDispatcher{TSource}(IObservable{TSource})"/> methods that use the current CoreDispatcher.
     /// </remarks>
     [CLSCompliant(false)]
     public sealed class CoreDispatcherScheduler : LocalScheduler, ISchedulerPeriodic

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Platforms/UWP/EventPatternSource.cs

@@ -18,7 +18,7 @@ namespace System.Reactive
         {
             add
             {
-                Add(value, (o, e) => value(o, e));
+                Add(value, (o, e) => value(o!, e));
             }
 
             remove

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Linq/CoreDispatcherObservable.cs

@@ -18,7 +18,7 @@ namespace System.Reactive.Linq
     [CLSCompliant(false)]
     public static class CoreDispatcherObservable
     {
-        #region ObserveOn[Dispatcher]
+        #region ObserveOn[CoreDispatcher]
 
         /// <summary>
         /// Wraps the source sequence in order to run its observer callbacks on the specified dispatcher.
@@ -150,9 +150,9 @@ namespace System.Reactive.Linq
             return Synchronization.ObserveOn(source, new CoreDispatcherScheduler(CoreDispatcherScheduler.Current.Dispatcher, priority));
         }
 
-#endregion
+        #endregion
 
-        #region SubscribeOn[Dispatcher]
+        #region SubscribeOn[CoreDispatcher]
 
         /// <summary>
         /// Wraps the source sequence in order to run its subscription and unsubscription logic on the specified dispatcher.

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Linq/WindowsObservable.Events.cs

@@ -111,7 +111,7 @@ namespace System.Reactive.Linq
                 throw new ArgumentNullException(nameof(source));
             }
 
-            return new EventPatternSource<TSender, TEventArgs>(source, static (h, evt) => h(evt.Sender, evt.EventArgs));
+            return new EventPatternSource<TSender, TEventArgs>(source, static (h, evt) => h(evt.Sender!, evt.EventArgs));
         }
     }
 }