diff --git a/Source/ReactiveProperty.Core/IReactiveProperty.cs b/Source/ReactiveProperty.Core/IReactiveProperty.cs index 237000f3..bf34dfd5 100644 --- a/Source/ReactiveProperty.Core/IReactiveProperty.cs +++ b/Source/ReactiveProperty.Core/IReactiveProperty.cs @@ -12,7 +12,7 @@ public interface IReactiveProperty : IReadOnlyReactiveProperty, IHasErrors, INot /// Gets or sets the value. /// /// The value. - new object Value { get; set; } + new object? Value { get; set; } } /// @@ -25,6 +25,6 @@ public interface IReactiveProperty : IReactiveProperty, IReadOnlyReactiveProp /// Gets or sets the value. /// /// The value. - new T Value { get; set; } + new T? Value { get; set; } } } diff --git a/Source/ReactiveProperty.Core/IReadOnlyReactiveProperty.cs b/Source/ReactiveProperty.Core/IReadOnlyReactiveProperty.cs index adef3d3c..b27b8133 100644 --- a/Source/ReactiveProperty.Core/IReadOnlyReactiveProperty.cs +++ b/Source/ReactiveProperty.Core/IReadOnlyReactiveProperty.cs @@ -11,7 +11,7 @@ public interface IReadOnlyReactiveProperty : INotifyPropertyChanged /// Gets the value. /// /// The value. - object Value { get; } + object? Value { get; } } /// @@ -23,6 +23,6 @@ public interface IReadOnlyReactiveProperty : IReadOnlyReactiveProperty, I /// Gets the value. /// /// The value. - new T Value { get; } + new T? Value { get; } } } diff --git a/Source/ReactiveProperty.Core/Internals/AccessorCache.cs b/Source/ReactiveProperty.Core/Internals/AccessorCache.cs index 85114a74..5344b357 100644 --- a/Source/ReactiveProperty.Core/Internals/AccessorCache.cs +++ b/Source/ReactiveProperty.Core/Internals/AccessorCache.cs @@ -11,8 +11,8 @@ namespace Reactive.Bindings.Internals /// The type of the type. internal static class AccessorCache { - private static readonly Dictionary s_getCache = new Dictionary(); - private static readonly Dictionary s_setCache = new Dictionary(); + private static readonly Dictionary s_getCache = new(); + private static readonly Dictionary s_setCache = new(); /// /// Lookups the get. @@ -24,7 +24,7 @@ internal static class AccessorCache public static Func LookupGet(Expression> propertySelector, out string propertyName) { propertyName = ExpressionTreeUtils.GetPropertyName(propertySelector); - Delegate accessor; + Delegate? accessor; lock (s_getCache) { @@ -48,7 +48,7 @@ public static Func LookupGet(Expression LookupNestedGet(Expression> propertySelector, out string propertyName) { propertyName = ExpressionTreeUtils.GetPropertyPath(propertySelector); - Delegate accessor; + Delegate? accessor; lock (s_getCache) { @@ -69,10 +69,10 @@ public static Func LookupNestedGet(ExpressionThe property selector. /// Name of the property. /// - public static Action LookupSet(Expression> propertySelector, out string propertyName) + public static Action LookupSet(Expression> propertySelector, out string propertyName) { propertyName = ExpressionTreeUtils.GetPropertyName(propertySelector); - Delegate accessor; + Delegate? accessor; lock (s_setCache) { @@ -83,10 +83,10 @@ public static Action LookupSet(Expression)accessor; + return (Action)accessor; } - private static Delegate CreateSetAccessor(Expression> propertySelector) + private static Delegate CreateSetAccessor(Expression> propertySelector) { var propertyInfo = (PropertyInfo)((MemberExpression)propertySelector.Body).Member; var selfParameter = Expression.Parameter(typeof(TType), "self"); @@ -99,9 +99,9 @@ private static Delegate CreateSetAccessor(Expression _accessorCacheTypeCache = new Dictionary(); - private static readonly Dictionary> _getCache = new Dictionary>(); - private static readonly Dictionary> _setCache = new Dictionary>(); + private static readonly Dictionary _accessorCacheTypeCache = new(); + private static readonly Dictionary> _getCache = new(); + private static readonly Dictionary> _setCache = new(); private static Dictionary GetGetCacheByType(Type type) { diff --git a/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs b/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs index 0bcf5438..e5bd859e 100644 --- a/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs +++ b/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs @@ -9,48 +9,46 @@ internal static class ExpressionTreeUtils { public static string GetPropertyPath(Expression> propertySelector) { - if (!(propertySelector.Body is MemberExpression memberExpression)) - { - if (!(propertySelector.Body is UnaryExpression unaryExpression)) { throw new ArgumentException(nameof(propertySelector)); } - memberExpression = unaryExpression.Operand as MemberExpression; - if (memberExpression == null) { throw new ArgumentException(nameof(propertySelector)); } - } - + var memberExpression = GetMemberExpressionFromPropertySelector(propertySelector); var tokens = new LinkedList(); while (memberExpression != null) { tokens.AddFirst(memberExpression.Member.Name); - memberExpression = memberExpression.Expression as MemberExpression; + if (memberExpression is not MemberExpression nextToken) { break; } + memberExpression = nextToken; } return string.Join(".", tokens); } - public static string GetPropertyName(Expression> propertySelector) + public static string GetPropertyName(Expression> propertySelector) => + GetMemberExpressionFromPropertySelector(propertySelector).Member.Name; + + private static MemberExpression GetMemberExpressionFromPropertySelector(Expression> propertySelector) { - if (!(propertySelector.Body is MemberExpression memberExpression)) + if (propertySelector.Body is not MemberExpression memberExpression) { - if (!(propertySelector.Body is UnaryExpression unaryExpression)) { throw new ArgumentException(nameof(propertySelector)); } - memberExpression = unaryExpression.Operand as MemberExpression; - if (memberExpression == null) { throw new ArgumentException(nameof(propertySelector)); } + if (propertySelector.Body is not UnaryExpression unaryExpression) { throw new ArgumentException(nameof(propertySelector)); } + if (unaryExpression.Operand is not MemberExpression memberExpressionForUnary) { throw new ArgumentException(nameof(propertySelector)); } + memberExpression = memberExpressionForUnary; } - return memberExpression.Member.Name; + return memberExpression; } public static bool IsNestedPropertyPath(Expression> propertySelector) { if (propertySelector.Body is MemberExpression member) { - return !(member.Expression is ParameterExpression); + return member.Expression is not ParameterExpression; }; if (propertySelector.Body is UnaryExpression unary) { if (unary.Operand is MemberExpression unaryMember) { - return !(unaryMember.Expression is ParameterExpression); + return unaryMember.Expression is not ParameterExpression; } } diff --git a/Source/ReactiveProperty.Core/Internals/IObserverLinkedList.cs b/Source/ReactiveProperty.Core/Internals/IObserverLinkedList.cs index 08de5c03..3f2d2938 100644 --- a/Source/ReactiveProperty.Core/Internals/IObserverLinkedList.cs +++ b/Source/ReactiveProperty.Core/Internals/IObserverLinkedList.cs @@ -6,7 +6,7 @@ namespace Reactive.Bindings.Internals { internal interface IObserverLinkedList { - void UnsubscribeNode(ObserverNode node); + void UnsubscribeNode(ObserverNode node); } } diff --git a/Source/ReactiveProperty.Core/Internals/ObserverNode.cs b/Source/ReactiveProperty.Core/Internals/ObserverNode.cs index 3782ea9b..d624d259 100644 --- a/Source/ReactiveProperty.Core/Internals/ObserverNode.cs +++ b/Source/ReactiveProperty.Core/Internals/ObserverNode.cs @@ -10,9 +10,9 @@ internal sealed class ObserverNode : IObserver, IDisposable private readonly IObserver _observer; private IObserverLinkedList _list; - public ObserverNode Previous { get; set; } + public ObserverNode? Previous { get; set; } - public ObserverNode Next { get; set; } + public ObserverNode? Next { get; set; } public ObserverNode(IObserverLinkedList list, IObserver observer) { @@ -38,7 +38,7 @@ public void OnCompleted() [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value", Justification = "")] public void Dispose() { - var sourceList = Interlocked.Exchange(ref _list, null); + var sourceList = Interlocked.Exchange(ref _list, null!); if (sourceList != null) { sourceList.UnsubscribeNode(this); diff --git a/Source/ReactiveProperty.Core/ReactiveProperty.Core.csproj b/Source/ReactiveProperty.Core/ReactiveProperty.Core.csproj index ef5e77e4..b2c32f77 100644 --- a/Source/ReactiveProperty.Core/ReactiveProperty.Core.csproj +++ b/Source/ReactiveProperty.Core/ReactiveProperty.Core.csproj @@ -2,9 +2,10 @@ ReactiveProperty.Core - netstandard2.0 + netstandard2.0;netcoreapp3.1;net5.0 ReactiveProperty.Core true + enable key.snk ReactiveProperty.Core includes minimum core classes such as ReactivePropertySlim and ReadOnlyReactivePropertySlim. diff --git a/Source/ReactiveProperty.Core/ReactivePropertySlim.cs b/Source/ReactiveProperty.Core/ReactivePropertySlim.cs index ef76be56..78910b19 100644 --- a/Source/ReactiveProperty.Core/ReactivePropertySlim.cs +++ b/Source/ReactiveProperty.Core/ReactivePropertySlim.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Runtime.ExceptionServices; +using System.Security.Cryptography.X509Certificates; using System.Threading; using Reactive.Bindings.Internals; @@ -18,24 +19,24 @@ public class ReactivePropertySlim : IReactiveProperty, IObserverLinkedList private const int IsDisposedFlagNumber = 1 << 9; // (reserve 0 ~ 8) // minimize field count - private T _latestValue; + private T? _latestValue; private ReactivePropertyMode _mode; // None = 0, DistinctUntilChanged = 1, RaiseLatestValueOnSubscribe = 2, Disposed = (1 << 9) private readonly IEqualityComparer _equalityComparer; - private ObserverNode _root; - private ObserverNode _last; + private ObserverNode? _root; + private ObserverNode? _last; /// /// Occurs when a property value changes. /// /// - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; /// /// Gets or sets the value. /// /// The value. - public T Value + public T? Value { get { @@ -44,7 +45,15 @@ public T Value set { - if (IsDistinctUntilChanged && _equalityComparer.Equals(_latestValue, value)) + static bool equals(IEqualityComparer comparer, T? latestValue, T? value) => (latestValue, value) switch + { + (null, null) => true, + (null, { }) => false, + ({ }, null) => false, + ({ } x, { } y) => comparer.Equals(x, y), + }; + + if (IsDistinctUntilChanged && equals(_equalityComparer, _latestValue, Value)) { return; } @@ -64,7 +73,7 @@ public T Value /// true if this instance is disposed; otherwise, false. public bool IsDisposed => (int)_mode == IsDisposedFlagNumber; - object IReactiveProperty.Value + object? IReactiveProperty.Value { get { @@ -73,7 +82,7 @@ object IReactiveProperty.Value set { - Value = (T)value; + Value = (T?)value; } } @@ -105,14 +114,14 @@ object IReadOnlyReactiveProperty.Value /// The initial value. /// The mode. /// The equality comparer. - public ReactivePropertySlim(T initialValue = default, ReactivePropertyMode mode = ReactivePropertyMode.Default, IEqualityComparer equalityComparer = null) + public ReactivePropertySlim(T? initialValue = default, ReactivePropertyMode mode = ReactivePropertyMode.Default, IEqualityComparer? equalityComparer = null) { _latestValue = initialValue; _mode = mode; _equalityComparer = equalityComparer ?? EqualityComparer.Default; } - private void OnNextAndRaiseValueChanged(ref T value) + private void OnNextAndRaiseValueChanged(ref T? value) { // call source.OnNext var node = _root; @@ -169,7 +178,7 @@ public IDisposable Subscribe(IObserver observer) return next; } - void IObserverLinkedList.UnsubscribeNode(ObserverNode node) + void IObserverLinkedList.UnsubscribeNode(ObserverNode node) { if (node == _root) { @@ -231,7 +240,7 @@ public override string ToString() IObservable IHasErrors.ObserveHasErrors => throw new NotSupportedException(); - event EventHandler INotifyDataErrorInfo.ErrorsChanged + event EventHandler? INotifyDataErrorInfo.ErrorsChanged { add { @@ -241,7 +250,7 @@ event EventHandler INotifyDataErrorInfo.ErrorsChange } } - IEnumerable INotifyDataErrorInfo.GetErrors(string propertyName) + IEnumerable INotifyDataErrorInfo.GetErrors(string? propertyName) { return System.Linq.Enumerable.Empty(); } @@ -251,26 +260,25 @@ IEnumerable INotifyDataErrorInfo.GetErrors(string propertyName) /// /// /// - /// /// public class ReadOnlyReactivePropertySlim : IReadOnlyReactiveProperty, IObserverLinkedList, IObserver { private const int IsDisposedFlagNumber = 1 << 9; // (reserve 0 ~ 8) // minimize field count - private T _latestValue; + private T? _latestValue; private IDisposable _sourceSubscription; private ReactivePropertyMode _mode; // None = 0, DistinctUntilChanged = 1, RaiseLatestValueOnSubscribe = 2, Disposed = (1 << 9) private readonly IEqualityComparer _equalityComparer; - private ObserverNode _root; - private ObserverNode _last; + private ObserverNode? _root; + private ObserverNode? _last; /// /// Occurs when a property value changes. /// /// - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; /// /// Gets the value. @@ -305,7 +313,7 @@ public T Value /// The initial value. /// The mode. /// The equality comparer. - public ReadOnlyReactivePropertySlim(IObservable source, T initialValue = default, ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, IEqualityComparer equalityComparer = null) + public ReadOnlyReactivePropertySlim(IObservable source, T? initialValue = default, ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, IEqualityComparer? equalityComparer = null) { _latestValue = initialValue; _mode = mode; @@ -355,7 +363,7 @@ public IDisposable Subscribe(IObserver observer) return next; } - void IObserverLinkedList.UnsubscribeNode(ObserverNode node) + void IObserverLinkedList.UnsubscribeNode(ObserverNode node) { if (node == _root) { @@ -455,7 +463,6 @@ public override string ToString() /// /// /// - /// /// public static class ReadOnlyReactivePropertySlim { @@ -468,7 +475,7 @@ public static class ReadOnlyReactivePropertySlim /// The mode. /// The equality comparer. /// - public static ReadOnlyReactivePropertySlim ToReadOnlyReactivePropertySlim(this IObservable source, T initialValue = default, ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, IEqualityComparer equalityComparer = null) + public static ReadOnlyReactivePropertySlim ToReadOnlyReactivePropertySlim(this IObservable source, T? initialValue = default, ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, IEqualityComparer? equalityComparer = null) { return new ReadOnlyReactivePropertySlim(source, initialValue, mode, equalityComparer); } diff --git a/Source/ReactiveProperty.NETStandard/AsyncReactiveCommand.cs b/Source/ReactiveProperty.NETStandard/AsyncReactiveCommand.cs index 80e17a70..c449cbdf 100644 --- a/Source/ReactiveProperty.NETStandard/AsyncReactiveCommand.cs +++ b/Source/ReactiveProperty.NETStandard/AsyncReactiveCommand.cs @@ -70,7 +70,7 @@ public class AsyncReactiveCommand : ICommand, IDisposable /// Occurs when changes occur that affect whether or not the command should execute. /// /// - public event EventHandler CanExecuteChanged; + public event EventHandler? CanExecuteChanged; private readonly object gate = new object(); private readonly IReactiveProperty canExecute; @@ -103,7 +103,7 @@ public AsyncReactiveCommand(IObservable canExecuteSource) /// /// CanExecute is automatically changed when executing to false and finished to true. /// - public AsyncReactiveCommand(IObservable canExecuteSource, IReactiveProperty sharedCanExecute) + public AsyncReactiveCommand(IObservable canExecuteSource, IReactiveProperty? sharedCanExecute) { canExecute = sharedCanExecute ?? new ReactivePropertySlim(true); sourceSubscription = canExecute.CombineLatest(canExecuteSource, (x, y) => x && y) @@ -140,7 +140,7 @@ public bool CanExecute() /// /// Return current canExecute status. parameter is ignored. /// - bool ICommand.CanExecute(object parameter) + bool ICommand.CanExecute(object? parameter) { return isDisposed ? false : isCanExecute; } @@ -148,12 +148,12 @@ bool ICommand.CanExecute(object parameter) /// /// Push parameter to subscribers, when executing CanExecuting is changed to false. /// - public async void Execute(T parameter) => await ExecuteAsync(parameter); + public async void Execute(T? parameter) => await ExecuteAsync(parameter); /// /// Push parameter to subscribers, when executing CanExecuting is changed to false. /// - public async Task ExecuteAsync(T parameter) + public async Task ExecuteAsync(T? parameter) { if (isCanExecute) { @@ -195,7 +195,7 @@ public async Task ExecuteAsync(T parameter) /// /// Push parameter to subscribers, when executing CanExecuting is changed to false. /// - void ICommand.Execute(object parameter) => Execute((T)parameter); + void ICommand.Execute(object? parameter) => Execute((T?)parameter); /// /// Subscribe execute. @@ -300,7 +300,7 @@ public static AsyncReactiveCommand ToAsyncReactiveCommand(this IReactivePr /// Action /// Handling of the subscription. /// Same of self argument - public static AsyncReactiveCommand WithSubscribe(this AsyncReactiveCommand self, Func asyncAction, Action postProcess = null) + public static AsyncReactiveCommand WithSubscribe(this AsyncReactiveCommand self, Func asyncAction, Action? postProcess = null) { var d = self.Subscribe(asyncAction); postProcess?.Invoke(d); @@ -315,7 +315,7 @@ public static AsyncReactiveCommand WithSubscribe(this AsyncReactiveCommand self, /// Action /// Handling of the subscription. /// Same of self argument - public static AsyncReactiveCommand WithSubscribe(this AsyncReactiveCommand self, Func asyncAction, Action postProcess = null) + public static AsyncReactiveCommand WithSubscribe(this AsyncReactiveCommand self, Func asyncAction, Action? postProcess = null) { var d = self.Subscribe(asyncAction); postProcess?.Invoke(d); diff --git a/Source/ReactiveProperty.NETStandard/Binding/RxBindingExtensions.cs b/Source/ReactiveProperty.NETStandard/Binding/RxBindingExtensions.cs index cecd40af..c7864671 100644 --- a/Source/ReactiveProperty.NETStandard/Binding/RxBindingExtensions.cs +++ b/Source/ReactiveProperty.NETStandard/Binding/RxBindingExtensions.cs @@ -30,59 +30,52 @@ public static class RxBindingExtensions /// source error value. /// Release binding disposable. public static IDisposable BindTo( - this ReactiveProperty self, + this ReactiveProperty self, TTarget target, Expression> propertySelector, BindingMode mode = BindingMode.OneWay, - Func convert = null, - Func convertBack = null, - IObservable targetUpdateTrigger = null, - TProperty propertyFallbackValue = default(TProperty), - T sourceFallbackValue = default(T)) + Func? convert = null, + Func? convertBack = null, + IObservable? targetUpdateTrigger = null, + TProperty? propertyFallbackValue = default, + T? sourceFallbackValue = default) { if (convert == null) { - convert = value => (TProperty)Convert.ChangeType(value, typeof(TProperty)); + convert = value => (TProperty?)Convert.ChangeType(value, typeof(TProperty)); } if (convertBack == null) { - convertBack = value => (T)Convert.ChangeType(value, typeof(T)); + convertBack = value => (T?)Convert.ChangeType(value, typeof(T)); } - switch (mode) + return mode switch { - case BindingMode.OneWay: - return CreateOneWayBinding( - self, - target, - propertySelector, - convert, - propertyFallbackValue); - - case BindingMode.TwoWay: - return CreateTowWayBinding( - self, - target, - propertySelector, - convert, - convertBack, - targetUpdateTrigger, - propertyFallbackValue, - sourceFallbackValue); - - case BindingMode.OneWayToSource: - return CreateOneWayToSourceBinding( - self, - target, - propertySelector, - convertBack, - targetUpdateTrigger, - sourceFallbackValue); - - default: - throw new NotSupportedException(); - } + BindingMode.OneWay => CreateOneWayBinding( + self, + target, + propertySelector, + convert, + propertyFallbackValue), + BindingMode.TwoWay => CreateTowWayBinding( + self, + target, + propertySelector, + convert, + convertBack, + targetUpdateTrigger, + propertyFallbackValue, + sourceFallbackValue), + BindingMode.OneWayToSource => CreateOneWayToSourceBinding( + self, + target, + propertySelector, + convertBack, + targetUpdateTrigger, + sourceFallbackValue), + _ => throw new NotSupportedException(), + }; } /// @@ -101,12 +94,12 @@ public static IDisposable BindTo( this ReadOnlyReactiveProperty self, TTarget target, Expression> propertySelector, - Func convert = null, - TProperty propertyFallbackValue = default(TProperty)) + Func? convert = null, + TProperty? propertyFallbackValue = default) { if (convert == null) { - convert = value => (TProperty)Convert.ChangeType(value, typeof(TProperty)); + convert = value => (TProperty?)Convert.ChangeType(value, typeof(TProperty)); } return CreateOneWayBinding( @@ -136,22 +129,27 @@ public static IDisposable BindTo( public static IDisposable BindTo( this ReactivePropertySlim self, TTarget target, - Expression> propertySelector, + Expression> propertySelector, BindingMode mode = BindingMode.OneWay, - Func convert = null, - Func convertBack = null, - IObservable targetUpdateTrigger = null, - TProperty propertyFallbackValue = default(TProperty), - T sourceFallbackValue = default(T)) + Func? convert = null, + Func? convertBack = null, + IObservable? targetUpdateTrigger = null, + TProperty? propertyFallbackValue = default, + T? sourceFallbackValue = default) { + if (self == null) + { + throw new ArgumentNullException(nameof(self)); + } + if (convert == null) { - convert = value => (TProperty)Convert.ChangeType(value, typeof(TProperty)); + convert = value => (TProperty?)Convert.ChangeType(value, typeof(TProperty)); } if (convertBack == null) { - convertBack = value => (T)Convert.ChangeType(value, typeof(T)); + convertBack = value => (T?)Convert.ChangeType(value, typeof(T)); } switch (mode) @@ -202,15 +200,15 @@ public static IDisposable BindTo( /// target error value. /// Release binding disposable. public static IDisposable BindTo( - this ReadOnlyReactivePropertySlim self, + this ReadOnlyReactivePropertySlim self, TTarget target, - Expression> propertySelector, - Func convert = null, - TProperty propertyFallbackValue = default(TProperty)) + Expression> propertySelector, + Func? convert = null, + TProperty? propertyFallbackValue = default) { if (convert == null) { - convert = value => (TProperty)Convert.ChangeType(value, typeof(TProperty)); + convert = value => (TProperty?)Convert.ChangeType(value, typeof(TProperty)); } return CreateOneWayBinding( @@ -221,7 +219,13 @@ public static IDisposable BindTo( propertyFallbackValue); } - private static IDisposable CreateOneWayToSourceBinding(IReactiveProperty self, TTarget target, Expression> propertySelector, Func convertBack, IObservable targetUpdateTrigger, T sourceFallbackValue) + private static IDisposable CreateOneWayToSourceBinding( + IReactiveProperty self, + TTarget target, + Expression> propertySelector, + Func convertBack, + IObservable targetUpdateTrigger, + T? sourceFallbackValue) { var propertyName = default(string); if (targetUpdateTrigger == null) @@ -243,7 +247,12 @@ private static IDisposable CreateOneWayToSourceBinding(IR }); } - private static IDisposable CreateOneWayBinding(IObservable self, TTarget target, Expression> propertySelector, Func convert, TProperty propertyFallbackValue) + private static IDisposable CreateOneWayBinding( + IObservable self, + TTarget target, + Expression> propertySelector, + Func? convert, + TProperty? propertyFallbackValue) { var propertyName = default(string); return self @@ -252,7 +261,7 @@ private static IDisposable CreateOneWayBinding(IObservabl var setter = AccessorCache.LookupSet(propertySelector, out propertyName); try { - setter(target, convert(value)); + setter(target, convert == null ? default : convert.Invoke(value)); } catch (Exception ex) { @@ -262,7 +271,15 @@ private static IDisposable CreateOneWayBinding(IObservabl }); } - private static IDisposable CreateTowWayBinding(IReactiveProperty self, TTarget target, Expression> propertySelector, Func convert, Func convertBack, IObservable targetUpdateTrigger, TProperty propertyFallbackValue, T sourceFallbackValue) + private static IDisposable CreateTowWayBinding( + IReactiveProperty self, + TTarget target, + Expression> propertySelector, + Func? convert, + Func? convertBack, + IObservable? targetUpdateTrigger, + TProperty? propertyFallbackValue, + T? sourceFallbackValue) { if (targetUpdateTrigger == null) { diff --git a/Source/ReactiveProperty.NETStandard/Extensions/INotifyCollectionChangedExtensions.cs b/Source/ReactiveProperty.NETStandard/Extensions/INotifyCollectionChangedExtensions.cs index 1a1d6851..5f123137 100644 --- a/Source/ReactiveProperty.NETStandard/Extensions/INotifyCollectionChangedExtensions.cs +++ b/Source/ReactiveProperty.NETStandard/Extensions/INotifyCollectionChangedExtensions.cs @@ -31,10 +31,10 @@ public static IObservable CollectionChangedAsO /// /// Observe CollectionChanged:Add and take single item. /// - public static IObservable ObserveAddChanged(this INotifyCollectionChanged source) => + public static IObservable ObserveAddChanged(this INotifyCollectionChanged source) => source.CollectionChangedAsObservable() .Where(e => e.Action == NotifyCollectionChangedAction.Add) - .Select(e => (T)e.NewItems[0]); + .Select(e => (T?)e.NewItems[0]); /// /// Observe CollectionChanged:Add. diff --git a/Source/ReactiveProperty.NETStandard/Extensions/INotifyPropertyChangedExtensions.cs b/Source/ReactiveProperty.NETStandard/Extensions/INotifyPropertyChangedExtensions.cs index 0e9d2697..68e03798 100644 --- a/Source/ReactiveProperty.NETStandard/Extensions/INotifyPropertyChangedExtensions.cs +++ b/Source/ReactiveProperty.NETStandard/Extensions/INotifyPropertyChangedExtensions.cs @@ -347,8 +347,7 @@ public static ReactivePropertySlim ToReactivePropertySlimAsSynchronized { var result = new ReactivePropertySlim(mode: mode); var observer = PropertyObservable.CreateFromPropertySelector(subject, propertySelector); - IDisposable disposable = null; - disposable = convert(subject.ObserveProperty(propertySelector, isPushCurrentValueAtFirst: true)) + var disposable = convert(subject.ObserveProperty(propertySelector, isPushCurrentValueAtFirst: true)) .Subscribe(x => result.Value = x); convertBack(result) .Subscribe(x => observer.SetPropertyPathValue(x), _ => disposable.Dispose(), () => disposable.Dispose()); @@ -358,8 +357,7 @@ public static ReactivePropertySlim ToReactivePropertySlimAsSynchronized { var setter = AccessorCache.LookupSet(propertySelector, out _); var result = new ReactivePropertySlim(mode: mode); - IDisposable disposable = null; - disposable = convert(subject.ObserveProperty(propertySelector, isPushCurrentValueAtFirst: true)) + var disposable = convert(subject.ObserveProperty(propertySelector, isPushCurrentValueAtFirst: true)) .Subscribe(x => result.Value = x); convertBack(result) .Subscribe(x => setter(subject, x), _ => disposable.Dispose(), () => disposable.Dispose()); diff --git a/Source/ReactiveProperty.NETStandard/Extensions/PairwiseObservableExtensions.cs b/Source/ReactiveProperty.NETStandard/Extensions/PairwiseObservableExtensions.cs index 46d16767..63a4c133 100644 --- a/Source/ReactiveProperty.NETStandard/Extensions/PairwiseObservableExtensions.cs +++ b/Source/ReactiveProperty.NETStandard/Extensions/PairwiseObservableExtensions.cs @@ -11,15 +11,17 @@ public static class ObservablePairwiseExtensions /// /// Projects old and new element of a sequence into a new form. /// - public static IObservable> Pairwise(this IObservable source) => - Pairwise(source, (x, y) => new OldNewPair(x, y)); + public static IObservable> Pairwise(this IObservable source) => +#pragma warning disable CS8619 // On this overload, a type parameter of IObservable is not null. + Pairwise(source, (x, y) => new OldNewPair(x, y)); +#pragma warning restore CS8619 /// /// Projects old and new element of a sequence into a new form. /// - public static IObservable Pairwise(this IObservable source, Func selector) + public static IObservable Pairwise(this IObservable source, Func selector) { - var result = Observable.Create(observer => + var result = Observable.Create(observer => { var prev = default(T); var isFirst = true; @@ -33,7 +35,7 @@ public static IObservable Pairwise(this IObservable source, Func OnErrorRetry( var empty = Observable.Empty(); var count = 0; - IObservable self = null; + IObservable? self = null; self = source.Catch((TException ex) => { onError(ex); return (++count < retryCount) ? (dueTime == TimeSpan.Zero) - ? self.SubscribeOn(Scheduler.CurrentThread) - : empty.Delay(dueTime, delayScheduler).Concat(self).SubscribeOn(Scheduler.CurrentThread) + ? self!.SubscribeOn(Scheduler.CurrentThread) + : empty.Delay(dueTime, delayScheduler).Concat(self!).SubscribeOn(Scheduler.CurrentThread) : Observable.Throw(ex); }); return self; diff --git a/Source/ReactiveProperty.NETStandard/Helpers/FilteredReadOnlyObservableCollection.cs b/Source/ReactiveProperty.NETStandard/Helpers/FilteredReadOnlyObservableCollection.cs index cc059f21..2464b650 100644 --- a/Source/ReactiveProperty.NETStandard/Helpers/FilteredReadOnlyObservableCollection.cs +++ b/Source/ReactiveProperty.NETStandard/Helpers/FilteredReadOnlyObservableCollection.cs @@ -56,12 +56,12 @@ public sealed class FilteredReadOnlyObservableCollection private int ItemsCount { get; set; } - private List InnerCollection { get; } = new List(); + private List InnerCollection { get; } = new List(); /// /// CollectionChanged event. /// - public event NotifyCollectionChangedEventHandler CollectionChanged; + public event NotifyCollectionChangedEventHandler? CollectionChanged; /// /// constructor @@ -209,7 +209,7 @@ private void Initialize() /// public TElement this[int index] => InnerCollection[index]; - object IList.this[int index] + object? IList.this[int index] { get { @@ -283,7 +283,7 @@ private void DisappearItem(int index) } } - int IList.Add(object value) + int IList.Add(object? value) { throw new NotSupportedException(); } @@ -293,16 +293,16 @@ void IList.Clear() throw new NotSupportedException(); } - bool IList.Contains(object value) => InnerCollection.Contains(value); + bool IList.Contains(object? value) => InnerCollection.Contains(value); - int IList.IndexOf(object value) => InnerCollection.IndexOf((TElement)value); + int IList.IndexOf(object? value) => InnerCollection.IndexOf((TElement?)value); - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { throw new NotSupportedException(); } - void IList.Remove(object value) + void IList.Remove(object? value) { throw new NotSupportedException(); } @@ -361,7 +361,7 @@ public static IFilteredReadOnlyObservableCollection ToFilteredReadOnlyObserva /// The scheduler. /// if set to true [dispose element]. /// - public static ReadOnlyReactiveCollection ToReadOnlyReactiveCollection(this IFilteredReadOnlyObservableCollection self, IScheduler scheduler = null, bool disposeElement = true) + public static ReadOnlyReactiveCollection ToReadOnlyReactiveCollection(this IFilteredReadOnlyObservableCollection self, IScheduler? scheduler = null, bool disposeElement = true) where T : class, INotifyPropertyChanged => self.ToReadOnlyReactiveCollection(x => x, scheduler, disposeElement); @@ -375,7 +375,7 @@ public static ReadOnlyReactiveCollection ToReadOnlyReactiveCollection(this /// The scheduler. /// if set to true [dispose element]. /// - public static ReadOnlyReactiveCollection ToReadOnlyReactiveCollection(this IFilteredReadOnlyObservableCollection self, Func converter, IScheduler scheduler = null, bool disposeElement = true) + public static ReadOnlyReactiveCollection ToReadOnlyReactiveCollection(this IFilteredReadOnlyObservableCollection self, Func converter, IScheduler? scheduler = null, bool disposeElement = true) where T : class, INotifyPropertyChanged => self.ToReadOnlyReactiveCollection( self.ToCollectionChanged(), diff --git a/Source/ReactiveProperty.NETStandard/Interactivity/DelegateConverter.cs b/Source/ReactiveProperty.NETStandard/Interactivity/DelegateConverter.cs index e05d6a73..d806865b 100644 --- a/Source/ReactiveProperty.NETStandard/Interactivity/DelegateConverter.cs +++ b/Source/ReactiveProperty.NETStandard/Interactivity/DelegateConverter.cs @@ -14,13 +14,13 @@ public abstract class DelegateConverter : ReactiveConverter /// /// /// - protected override IObservable OnConvert(IObservable source) => source.Select(OnConvert); + protected override IObservable OnConvert(IObservable source) => source.Select(OnConvert); /// /// converter method. /// /// source value /// dest value - protected abstract U OnConvert(T source); + protected abstract U? OnConvert(T? source); } } diff --git a/Source/ReactiveProperty.NETStandard/Interactivity/IEventToReactiveConverter.cs b/Source/ReactiveProperty.NETStandard/Interactivity/IEventToReactiveConverter.cs index b95de4d3..4f79c32c 100644 --- a/Source/ReactiveProperty.NETStandard/Interactivity/IEventToReactiveConverter.cs +++ b/Source/ReactiveProperty.NETStandard/Interactivity/IEventToReactiveConverter.cs @@ -14,13 +14,13 @@ public interface IEventToReactiveConverter /// Gets or sets the associate object. /// /// The associate object. - object AssociateObject { get; set; } + object? AssociateObject { get; set; } /// /// Converts the specified source. /// /// The source. /// - IObservable Convert(IObservable source); + IObservable Convert(IObservable source); } } diff --git a/Source/ReactiveProperty.NETStandard/Interactivity/ReactiveConverter.cs b/Source/ReactiveProperty.NETStandard/Interactivity/ReactiveConverter.cs index 972daacd..099cedda 100644 --- a/Source/ReactiveProperty.NETStandard/Interactivity/ReactiveConverter.cs +++ b/Source/ReactiveProperty.NETStandard/Interactivity/ReactiveConverter.cs @@ -17,20 +17,20 @@ public abstract class ReactiveConverter : IEventToReactiveConverter /// /// EventToReactiveCommand's AssociateObject /// - public object AssociateObject { get; set; } + public object? AssociateObject { get; set; } /// /// Converts the specified source. /// /// The source. /// - public IObservable Convert(IObservable source) => OnConvert(source.Cast()).Select(x => (object)x); + public IObservable Convert(IObservable source) => OnConvert(source.Cast()).Select(x => (object?)x); /// /// Converts /// /// source /// dest - protected abstract IObservable OnConvert(IObservable source); + protected abstract IObservable OnConvert(IObservable source); } } diff --git a/Source/ReactiveProperty.NETStandard/Internals/PropertyObservable.cs b/Source/ReactiveProperty.NETStandard/Internals/PropertyObservable.cs index 3f669f62..ef1eaa37 100644 --- a/Source/ReactiveProperty.NETStandard/Internals/PropertyObservable.cs +++ b/Source/ReactiveProperty.NETStandard/Internals/PropertyObservable.cs @@ -5,28 +5,28 @@ namespace Reactive.Bindings.Internals { - internal sealed class PropertyObservable : IObservable, IDisposable + internal sealed class PropertyObservable : IObservable, IDisposable { - private PropertyPathNode RootNode { get; set; } + private PropertyPathNode? RootNode { get; set; } internal void SetRootNode(PropertyPathNode rootNode) { RootNode?.SetCallback(null); rootNode?.SetCallback(RaisePropertyChanged); RootNode = rootNode; } - public TProperty GetPropertyPathValue() + public TProperty? GetPropertyPathValue() { var value = RootNode?.GetPropertyPathValue(); return value != null ? (TProperty)value : default; } - public string Path => RootNode?.Path; - public bool SetPropertyPathValue(TProperty value) => RootNode?.SetPropertyPathValue(value) ?? false; + public string? Path => RootNode?.Path; + public bool SetPropertyPathValue(TProperty? value) => RootNode?.SetPropertyPathValue(value) ?? false; public void SetSource(INotifyPropertyChanged source) => RootNode?.UpdateSource(source); private void RaisePropertyChanged() => _propertyChangedSource.OnNext(GetPropertyPathValue()); - private readonly Subject _propertyChangedSource = new Subject(); + private readonly Subject _propertyChangedSource = new Subject(); public void Dispose() { @@ -35,7 +35,7 @@ public void Dispose() RootNode = null; } - public IDisposable Subscribe(IObserver observer) => _propertyChangedSource.Subscribe(observer); + public IDisposable Subscribe(IObserver observer) => _propertyChangedSource.Subscribe(observer); } internal static class PropertyObservable diff --git a/Source/ReactiveProperty.NETStandard/Internals/PropertyPathNode.cs b/Source/ReactiveProperty.NETStandard/Internals/PropertyPathNode.cs index aaae20a9..7aae228a 100644 --- a/Source/ReactiveProperty.NETStandard/Internals/PropertyPathNode.cs +++ b/Source/ReactiveProperty.NETStandard/Internals/PropertyPathNode.cs @@ -8,11 +8,11 @@ namespace Reactive.Bindings.Internals internal class PropertyPathNode : IDisposable { private bool _isDisposed = false; - private Action _callback; - private Delegate _getAccessor; - private Delegate _setAccessor; + private Action? _callback; + private Delegate? _getAccessor; + private Delegate? _setAccessor; - public event EventHandler PropertyChanged; + public event EventHandler? PropertyChanged; public PropertyPathNode(string propertyName) { @@ -20,7 +20,7 @@ public PropertyPathNode(string propertyName) } public string PropertyName { get; } - public object Source { get; private set; } + public object? Source { get; private set; } private Type PrevSourceType { get; set; } public PropertyPathNode Next { get; private set; } public PropertyPathNode Prev { get; private set; } @@ -42,7 +42,7 @@ public PropertyPathNode InsertBefore(string propertyName) return Prev; } - public void UpdateSource(object source) + public void UpdateSource(object? source) { EnsureDispose(); Cleanup(); @@ -88,7 +88,7 @@ public object GetPropertyPathValue() return GetPropertyValue(); } - public bool SetPropertyPathValue(object value) + public bool SetPropertyPathValue(object? value) { if (Source == null) { @@ -111,7 +111,7 @@ public bool SetPropertyPathValue(object value) public override string ToString() => Path; - private void SourcePropertyChangedEventHandler(object sender, PropertyChangedEventArgs e) + private void SourcePropertyChangedEventHandler(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == PropertyName || string.IsNullOrEmpty(e.PropertyName)) { @@ -153,7 +153,7 @@ public static PropertyPathNode CreateFromPropertySelector( { if (!(propertySelector.Body is MemberExpression current)) { - throw new ArgumentException(); + throw new ArgumentException(nameof(propertySelector)); } var node = default(PropertyPathNode); diff --git a/Source/ReactiveProperty.NETStandard/Notifiers/BooleanNotifier.cs b/Source/ReactiveProperty.NETStandard/Notifiers/BooleanNotifier.cs index c993071a..a98671f6 100644 --- a/Source/ReactiveProperty.NETStandard/Notifiers/BooleanNotifier.cs +++ b/Source/ReactiveProperty.NETStandard/Notifiers/BooleanNotifier.cs @@ -14,7 +14,7 @@ public class BooleanNotifier : IObservable, INotifyPropertyChanged /// Occurs when a property value changes. /// /// - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; private readonly Subject boolTrigger = new Subject(); private bool boolValue; @@ -81,6 +81,6 @@ public void TurnOff() /// Called when [property changed]. /// /// Name of the property. - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } diff --git a/Source/ReactiveProperty.NETStandard/Notifiers/BusyNotifier.cs b/Source/ReactiveProperty.NETStandard/Notifiers/BusyNotifier.cs index cbdf6c62..fb0e135a 100644 --- a/Source/ReactiveProperty.NETStandard/Notifiers/BusyNotifier.cs +++ b/Source/ReactiveProperty.NETStandard/Notifiers/BusyNotifier.cs @@ -16,7 +16,7 @@ public class BusyNotifier : INotifyPropertyChanged, IObservable /// /// property changed event handler /// - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; private int ProcessCounter { get; set; } diff --git a/Source/ReactiveProperty.NETStandard/Notifiers/CountNotifier.cs b/Source/ReactiveProperty.NETStandard/Notifiers/CountNotifier.cs index f9f6414b..5d27b95e 100644 --- a/Source/ReactiveProperty.NETStandard/Notifiers/CountNotifier.cs +++ b/Source/ReactiveProperty.NETStandard/Notifiers/CountNotifier.cs @@ -44,7 +44,7 @@ public class CountNotifier : IObservable, INotifyPropertyCha /// Occurs when a property value changes. /// /// - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; private readonly int max; private int count; @@ -159,7 +159,7 @@ public void Decrement(int decrementCount = 1) /// public IDisposable Subscribe(IObserver observer) => statusChanged.Subscribe(observer); - private void OnPropertyChanged([CallerMemberName] string propertyName = null) => + private void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } diff --git a/Source/ReactiveProperty.NETStandard/Notifiers/MessageBroker.cs b/Source/ReactiveProperty.NETStandard/Notifiers/MessageBroker.cs index 1403657f..545c96a3 100644 --- a/Source/ReactiveProperty.NETStandard/Notifiers/MessageBroker.cs +++ b/Source/ReactiveProperty.NETStandard/Notifiers/MessageBroker.cs @@ -13,7 +13,7 @@ public interface IMessagePublisher /// /// Send Message to all receiver. /// - void Publish(T message); + void Publish(T? message); } /// @@ -24,7 +24,7 @@ public interface IMessageSubscriber /// /// Subscribe typed message. /// - IDisposable Subscribe(Action action); + IDisposable Subscribe(Action action); } /// @@ -79,17 +79,16 @@ public class MessageBroker : IMessageBroker, IDisposable /// /// Send Message to all receiver. /// - public void Publish(T message) + public void Publish(T? message) { - ImmutableList> notifier; + ImmutableList> notifier; lock (notifiers) { if (isDisposed) throw new ObjectDisposedException("AsyncMessageBroker"); - object _notifier; - if (notifiers.TryGetValue(typeof(T), out _notifier)) + if (notifiers.TryGetValue(typeof(T), out var _notifier)) { - notifier = (ImmutableList>)_notifier; + notifier = (ImmutableList>)_notifier; } else { @@ -107,7 +106,7 @@ public void Publish(T message) /// /// Subscribe typed message. /// - public IDisposable Subscribe(Action action) + public IDisposable Subscribe(Action action) { lock (notifiers) { @@ -116,13 +115,13 @@ public IDisposable Subscribe(Action action) object _notifier; if (!notifiers.TryGetValue(typeof(T), out _notifier)) { - var notifier = ImmutableList>.Empty; + var notifier = ImmutableList>.Empty; notifier = notifier.Add(action); notifiers.Add(typeof(T), notifier); } else { - var notifier = (ImmutableList>)_notifier; + var notifier = (ImmutableList>)_notifier; notifier = notifier.Add(action); notifiers[typeof(T)] = notifier; } @@ -149,9 +148,9 @@ public void Dispose() class Subscription : IDisposable { readonly MessageBroker parent; - readonly Action action; + readonly Action action; - public Subscription(MessageBroker parent, Action action) + public Subscription(MessageBroker parent, Action action) { this.parent = parent; this.action = action; @@ -179,7 +178,7 @@ public void Dispose() /// public class AsyncMessageBroker : IAsyncMessageBroker, IDisposable { - static readonly Task EmptyTask = Task.FromResult(null); + static readonly Task EmptyTask = Task.CompletedTask; /// /// AsyncMessageBroker in Global scope. @@ -192,9 +191,9 @@ public class AsyncMessageBroker : IAsyncMessageBroker, IDisposable /// /// Send Message to all receiver and await complete. /// - public Task PublishAsync(T message) + public Task PublishAsync(T? message) { - ImmutableList> notifier; + ImmutableList> notifier; lock (notifiers) { if (isDisposed) throw new ObjectDisposedException("AsyncMessageBroker"); @@ -202,7 +201,7 @@ public Task PublishAsync(T message) object _notifier; if (notifiers.TryGetValue(typeof(T), out _notifier)) { - notifier = (ImmutableList>)_notifier; + notifier = (ImmutableList>)_notifier; } else { @@ -222,7 +221,7 @@ public Task PublishAsync(T message) /// /// Subscribe typed message. /// - public IDisposable Subscribe(Func asyncAction) + public IDisposable Subscribe(Func asyncAction) { lock (notifiers) { @@ -231,13 +230,13 @@ public IDisposable Subscribe(Func asyncAction) object _notifier; if (!notifiers.TryGetValue(typeof(T), out _notifier)) { - var notifier = ImmutableList>.Empty; + var notifier = ImmutableList>.Empty; notifier = notifier.Add(asyncAction); notifiers.Add(typeof(T), notifier); } else { - var notifier = (ImmutableList>)_notifier; + var notifier = (ImmutableList>)_notifier; notifier = notifier.Add(asyncAction); notifiers[typeof(T)] = notifier; } @@ -264,9 +263,9 @@ public void Dispose() class Subscription : IDisposable { readonly AsyncMessageBroker parent; - readonly Func asyncAction; + readonly Func asyncAction; - public Subscription(AsyncMessageBroker parent, Func asyncAction) + public Subscription(AsyncMessageBroker parent, Func asyncAction) { this.parent = parent; this.asyncAction = asyncAction; @@ -279,7 +278,7 @@ public void Dispose() object _notifier; if (parent.notifiers.TryGetValue(typeof(T), out _notifier)) { - var notifier = (ImmutableList>)_notifier; + var notifier = (ImmutableList>)_notifier; notifier = notifier.Remove(asyncAction); parent.notifiers[typeof(T)] = notifier; @@ -297,12 +296,12 @@ public static class MessageBrokerExtensions /// /// Convert IMessageSubscriber.Subscribe to Observable. /// - public static IObservable ToObservable(this IMessageSubscriber messageSubscriber) + public static IObservable ToObservable(this IMessageSubscriber messageSubscriber) { - return Observable.Create(observer => + return Observable.Create(observer => { var gate = new object(); - var d = messageSubscriber.Subscribe(x => + var d = messageSubscriber.Subscribe(x => { // needs synchronize lock (gate) diff --git a/Source/ReactiveProperty.NETStandard/ObservableAsyncHandler.cs b/Source/ReactiveProperty.NETStandard/ObservableAsyncHandler.cs index 21e1ba7e..6be146d7 100644 --- a/Source/ReactiveProperty.NETStandard/ObservableAsyncHandler.cs +++ b/Source/ReactiveProperty.NETStandard/ObservableAsyncHandler.cs @@ -14,16 +14,15 @@ namespace Reactive.Bindings /// public class ObservableAsyncHandler : IDisposable, IObserver, ICriticalNotifyCompletion { - private static readonly Action cancelDelegate = DisposeSelf; + private static readonly Action cancelDelegate = DisposeSelf; private static readonly SendOrPostCallback syncContextPost = PostInvoke; private IDisposable subscription; private CancellationTokenRegistration cancellationTokenRegistration; - private CancellationToken token; private bool completed; - private T currentValue; - private ExceptionDispatchInfo exception; - private Action continuation; - private SynchronizationContext context; + private T? currentValue; + private ExceptionDispatchInfo? exception; + private Action? continuation; + private SynchronizationContext? context; private readonly object gate = new object(); /// @@ -50,16 +49,16 @@ public async Task AsTask() await this; } - private static void DisposeSelf(object state) + private static void DisposeSelf(object? state) { - var self = (ObservableAsyncHandler)state; - self.Dispose(); + var self = (ObservableAsyncHandler?)state; + self?.Dispose(); } - private static void PostInvoke(object state) + private static void PostInvoke(object? state) { - var continuation = (Action)state; - continuation(); + var continuation = (Action?)state; + continuation?.Invoke(); } /// @@ -134,7 +133,7 @@ public bool IsCompleted { get { - return (exception != null || token.IsCancellationRequested || completed); + return (exception != null || completed); } } @@ -151,8 +150,6 @@ public T GetResult() return default(T); } - token.ThrowIfCancellationRequested(); - if (completed) { throw new OperationCanceledException(); diff --git a/Source/ReactiveProperty.NETStandard/ReactiveCommand.cs b/Source/ReactiveProperty.NETStandard/ReactiveCommand.cs index 75f46b75..6451170a 100644 --- a/Source/ReactiveProperty.NETStandard/ReactiveCommand.cs +++ b/Source/ReactiveProperty.NETStandard/ReactiveCommand.cs @@ -66,9 +66,9 @@ public class ReactiveCommand : IObservable, ICommand, IDisposable /// /// ICommand#CanExecuteChanged /// - public event EventHandler CanExecuteChanged; + public event EventHandler? CanExecuteChanged; - private Subject Trigger { get; } = new Subject(); + private Subject Trigger { get; } = new Subject(); private IDisposable CanExecuteSubscription { get; } @@ -127,12 +127,12 @@ public ReactiveCommand(IObservable canExecuteSource, IScheduler scheduler, /// /// Return current canExecute status. parameter is ignored. /// - bool ICommand.CanExecute(object parameter) => IsCanExecute; + bool ICommand.CanExecute(object? parameter) => IsCanExecute; /// /// Push parameter to subscribers. /// - public void Execute(T parameter) + public void Execute(T? parameter) { Trigger.OnNext(parameter); } @@ -140,7 +140,7 @@ public void Execute(T parameter) /// /// Push parameter to subscribers. /// - void ICommand.Execute(object parameter) => Execute((T)parameter); + void ICommand.Execute(object? parameter) => Execute((T?)parameter); /// /// Subscribe execute. @@ -210,7 +210,7 @@ public static ReactiveCommand ToReactiveCommand(this IObservable can /// Action /// Handling of the subscription. /// Same of self argument - public static ReactiveCommand WithSubscribe(this ReactiveCommand self, Action onNext, Action postProcess = null) + public static ReactiveCommand WithSubscribe(this ReactiveCommand self, Action onNext, Action? postProcess = null) { var d = self.Subscribe(onNext); postProcess?.Invoke(d); @@ -225,7 +225,7 @@ public static ReactiveCommand WithSubscribe(this ReactiveCommand self, Action on /// Action /// Handling of the subscription. /// Same of self argument - public static ReactiveCommand WithSubscribe(this ReactiveCommand self, Action onNext, Action postProcess = null) + public static ReactiveCommand WithSubscribe(this ReactiveCommand self, Action onNext, Action? postProcess = null) { var d = self.Subscribe(onNext); postProcess?.Invoke(d); diff --git a/Source/ReactiveProperty.NETStandard/ReactiveProperty.NETStandard.csproj b/Source/ReactiveProperty.NETStandard/ReactiveProperty.NETStandard.csproj index 4a52fd02..33c5a8ea 100644 --- a/Source/ReactiveProperty.NETStandard/ReactiveProperty.NETStandard.csproj +++ b/Source/ReactiveProperty.NETStandard/ReactiveProperty.NETStandard.csproj @@ -2,9 +2,10 @@ ReactiveProperty - netstandard2.0 + netstandard2.0;netcoreapp3.1;net5.0 ReactiveProperty true + enable key.snk ReactiveProperty is MVVM and Asynchronous Extensions for Reactive Extensions(System.Reactive). Target platform is .NET Standard 2.0. diff --git a/Source/ReactiveProperty.NETStandard/ReactiveProperty.cs b/Source/ReactiveProperty.NETStandard/ReactiveProperty.cs index 785a2e4d..fe46c87d 100644 --- a/Source/ReactiveProperty.NETStandard/ReactiveProperty.cs +++ b/Source/ReactiveProperty.NETStandard/ReactiveProperty.cs @@ -29,9 +29,9 @@ public class ReactiveProperty : IReactiveProperty, IObserverLinkedList /// /// Implements of INotifyPropertyChanged. /// - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; - private T LatestValue { get; set; } + private T? LatestValue { get; set; } /// /// Gets a value indicating whether this instance is disposed. diff --git a/Source/ReactiveProperty.Platform.Shared/ObjectExtensions/ObserveEveryValueChangedExtensions.cs b/Source/ReactiveProperty.Platform.Shared/ObjectExtensions/ObserveEveryValueChangedExtensions.cs index f56ae03a..45b84e4f 100644 --- a/Source/ReactiveProperty.Platform.Shared/ObjectExtensions/ObserveEveryValueChangedExtensions.cs +++ b/Source/ReactiveProperty.Platform.Shared/ObjectExtensions/ObserveEveryValueChangedExtensions.cs @@ -7,6 +7,9 @@ namespace Reactive.Bindings.ObjectExtensions { + /// + /// ObserveEveryValueChanged extension methods + /// public static class ObserveEveryValueChangedExtensions { /// diff --git a/Source/SharedProperties.csproj b/Source/SharedProperties.csproj index a66785aa..fc022a52 100644 --- a/Source/SharedProperties.csproj +++ b/Source/SharedProperties.csproj @@ -11,7 +11,7 @@ ReactivePropertyIcon_100x100.png https://github.com/runceel/ReactiveProperty git - 8.0 + 9.0 true true snupkg diff --git a/Test/ReactiveProperty.NETStandard.Tests/Helpers/FilteredReadOnlyObservableCollectionTest.cs b/Test/ReactiveProperty.NETStandard.Tests/Helpers/FilteredReadOnlyObservableCollectionTest.cs index 3e32ccfc..b9a76b42 100644 --- a/Test/ReactiveProperty.NETStandard.Tests/Helpers/FilteredReadOnlyObservableCollectionTest.cs +++ b/Test/ReactiveProperty.NETStandard.Tests/Helpers/FilteredReadOnlyObservableCollectionTest.cs @@ -415,20 +415,20 @@ public bool IsRemoved public class RangedObservableCollection : ObservableCollection { - private bool _suppressNotification = false; + private bool suppressNotification = false; protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { - if (!_suppressNotification) base.OnCollectionChanged(e); + if (!suppressNotification) base.OnCollectionChanged(e); } public void AddRange(IEnumerable list) { if (list == null) throw new ArgumentNullException("list"); - _suppressNotification = true; - foreach (T item in list) Add(item); - _suppressNotification = false; + suppressNotification = true; + foreach (var item in list) Add(item); + suppressNotification = false; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }