diff --git a/Source/ReactiveProperty.Core/IReactiveProperty.cs b/Source/ReactiveProperty.Core/IReactiveProperty.cs
index a69ec1a4..56c42779 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; }
///
/// Forces the notify.
diff --git a/Source/ReactiveProperty.Core/IReadOnlyReactiveProperty.cs b/Source/ReactiveProperty.Core/IReadOnlyReactiveProperty.cs
index 13bbfc42..982bf8b3 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; }
}
///
diff --git a/Source/ReactiveProperty.Core/Internals/AccessorCache.cs b/Source/ReactiveProperty.Core/Internals/AccessorCache.cs
index 6505474e..9c4b4889 100644
--- a/Source/ReactiveProperty.Core/Internals/AccessorCache.cs
+++ b/Source/ReactiveProperty.Core/Internals/AccessorCache.cs
@@ -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)
{
@@ -72,7 +72,7 @@ public static Func LookupNestedGet(Expression LookupSet(Expression> propertySelector, out string propertyName)
{
propertyName = ExpressionTreeUtils.GetPropertyName(propertySelector);
- Delegate accessor;
+ Delegate? accessor;
lock (s_setCache)
{
@@ -113,7 +113,7 @@ private static Dictionary GetGetCacheByType(Type type)
}
var accessorType = GetAccessorCacheTypeByType(type);
- cache = (Dictionary)accessorType.GetField("s_getCache", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
+ cache = (Dictionary)accessorType.GetField("s_getCache", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null)!;
_getCache.Add(type, cache);
return cache;
}
@@ -129,7 +129,7 @@ private static Dictionary GetSetCacheByType(Type type)
}
var accessorType = GetAccessorCacheTypeByType(type);
- cache = (Dictionary)accessorType.GetField("s_setCache", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
+ cache = (Dictionary)accessorType.GetField("s_setCache", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null)!;
_setCache.Add(type, cache);
return cache;
}
@@ -182,7 +182,7 @@ public static Delegate LookupSet(Type type, string propertyName)
private static Delegate CreateAndCacheGetAccessor(Type type, string propertyName, Dictionary cache)
{
- var propertyInfo = type.GetProperty(propertyName);
+ var propertyInfo = type.GetProperty(propertyName) ?? throw new ArgumentException($"{propertyName} is not found on {type.FullName}");
var accessor = CreateGetAccessor(type, propertyInfo);
cache.Add(propertyName, accessor);
return accessor;
@@ -190,7 +190,7 @@ private static Delegate CreateAndCacheGetAccessor(Type type, string propertyName
private static Delegate CreateAndCacheSetAccessor(Type type, string propertyName, Dictionary cache)
{
- var propertyInfo = type.GetProperty(propertyName);
+ var propertyInfo = type.GetProperty(propertyName) ?? throw new ArgumentException($"{propertyName} is not found on {type.FullName}");
var accessor = CreateSetAccessor(type, propertyInfo);
cache.Add(propertyName, accessor);
return accessor;
diff --git a/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs b/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs
index c5e4be89..73d5e0e5 100644
--- a/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs
+++ b/Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs
@@ -9,9 +9,10 @@ internal static class ExpressionTreeUtils
{
public static string GetPropertyPath(Expression> propertySelector)
{
- if (!(propertySelector.Body is MemberExpression memberExpression))
+ var memberExpression = propertySelector.Body as MemberExpression;
+ if (memberExpression == null)
{
- if (!(propertySelector.Body is UnaryExpression unaryExpression)) { throw new ArgumentException(nameof(propertySelector)); }
+ if (propertySelector.Body is not UnaryExpression unaryExpression) { throw new ArgumentException(nameof(propertySelector)); }
memberExpression = unaryExpression.Operand as MemberExpression;
if (memberExpression == null) { throw new ArgumentException(nameof(propertySelector)); }
}
@@ -29,7 +30,8 @@ public static string GetPropertyPath(Expression(Expression> propertySelector)
{
- if (!(propertySelector.Body is MemberExpression memberExpression))
+ var memberExpression = propertySelector.Body as MemberExpression;
+ if (memberExpression == null)
{
if (!(propertySelector.Body is UnaryExpression unaryExpression)) { throw new ArgumentException(nameof(propertySelector)); }
memberExpression = unaryExpression.Operand as MemberExpression;
diff --git a/Source/ReactiveProperty.Core/Internals/ObserverNode.cs b/Source/ReactiveProperty.Core/Internals/ObserverNode.cs
index e1035f67..8fbb5ec5 100644
--- a/Source/ReactiveProperty.Core/Internals/ObserverNode.cs
+++ b/Source/ReactiveProperty.Core/Internals/ObserverNode.cs
@@ -8,11 +8,11 @@ namespace Reactive.Bindings.Internals;
internal sealed class ObserverNode : IObserver, IDisposable
{
private readonly IObserver _observer;
- private IObserverLinkedList _list;
+ 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)
{
diff --git a/Source/ReactiveProperty.Core/ReactivePropertySlim.cs b/Source/ReactiveProperty.Core/ReactivePropertySlim.cs
index c5e86abf..07df0eca 100644
--- a/Source/ReactiveProperty.Core/ReactivePropertySlim.cs
+++ b/Source/ReactiveProperty.Core/ReactivePropertySlim.cs
@@ -22,14 +22,14 @@ public class ReactivePropertySlim : IReactiveProperty, IObserverLinkedList
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.
@@ -64,7 +64,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,11 +73,11 @@ object IReactiveProperty.Value
set
{
- Value = (T)value;
+ Value = (T)value!;
}
}
- object IReadOnlyReactiveProperty.Value
+ object? IReadOnlyReactiveProperty.Value
{
get
{
@@ -105,7 +105,7 @@ 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;
@@ -162,7 +162,7 @@ public IDisposable Subscribe(IObserver observer)
}
else
{
- _last.Next = next;
+ _last!.Next = next;
next.Previous = _last;
_last = next;
}
@@ -216,7 +216,7 @@ public void Dispose()
/// Returns a that represents this instance.
///
/// A that represents this instance.
- public override string ToString()
+ public override string? ToString()
{
return (_latestValue == null)
? "null"
@@ -231,7 +231,7 @@ public override string ToString()
IObservable IHasErrors.ObserveHasErrors => throw new NotSupportedException();
- event EventHandler INotifyDataErrorInfo.ErrorsChanged
+ event EventHandler? INotifyDataErrorInfo.ErrorsChanged
{
add
{
@@ -241,7 +241,7 @@ event EventHandler INotifyDataErrorInfo.ErrorsChange
}
}
- IEnumerable INotifyDataErrorInfo.GetErrors(string propertyName)
+ IEnumerable INotifyDataErrorInfo.GetErrors(string? propertyName)
{
return System.Linq.Enumerable.Empty