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
///
///
- ///
///
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