Browse Source

Enable AvaloniaObject nullablity

pull/5955/head
Max Katz 5 years ago
parent
commit
4f82d510c5
  1. 39
      src/Avalonia.Base/AvaloniaObject.cs
  2. 4
      src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs
  3. 9
      src/Avalonia.Base/IAvaloniaObject.cs
  4. 2
      src/Avalonia.Styling/StyledElement.cs
  5. 4
      src/Avalonia.Styling/Styling/PropertySetterInstance.cs
  6. 4
      src/Avalonia.Styling/Styling/PropertySetterLazyInstance.cs

39
src/Avalonia.Base/AvaloniaObject.cs

@ -7,6 +7,8 @@ using Avalonia.Logging;
using Avalonia.PropertyStore; using Avalonia.PropertyStore;
using Avalonia.Threading; using Avalonia.Threading;
#nullable enable
namespace Avalonia namespace Avalonia
{ {
/// <summary> /// <summary>
@ -17,12 +19,12 @@ namespace Avalonia
/// </remarks> /// </remarks>
public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyPropertyChanged, IValueSink public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyPropertyChanged, IValueSink
{ {
private IAvaloniaObject _inheritanceParent; private IAvaloniaObject? _inheritanceParent;
private List<IDisposable> _directBindings; private List<IDisposable>? _directBindings;
private PropertyChangedEventHandler _inpcChanged; private PropertyChangedEventHandler? _inpcChanged;
private EventHandler<AvaloniaPropertyChangedEventArgs> _propertyChanged; private EventHandler<AvaloniaPropertyChangedEventArgs>? _propertyChanged;
private List<IAvaloniaObject> _inheritanceChildren; private List<IAvaloniaObject>? _inheritanceChildren;
private ValueStore _values; private ValueStore? _values;
private bool _batchUpdate; private bool _batchUpdate;
/// <summary> /// <summary>
@ -36,7 +38,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Raised when a <see cref="AvaloniaProperty"/> value changes on this object. /// Raised when a <see cref="AvaloniaProperty"/> value changes on this object.
/// </summary> /// </summary>
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged public event EventHandler<AvaloniaPropertyChangedEventArgs>? PropertyChanged
{ {
add { _propertyChanged += value; } add { _propertyChanged += value; }
remove { _propertyChanged -= value; } remove { _propertyChanged -= value; }
@ -58,7 +60,7 @@ namespace Avalonia
/// <value> /// <value>
/// The inheritance parent. /// The inheritance parent.
/// </value> /// </value>
protected IAvaloniaObject InheritanceParent protected IAvaloniaObject? InheritanceParent
{ {
get get
{ {
@ -289,7 +291,8 @@ namespace Avalonia
/// <returns>True if the property is animating, otherwise false.</returns> /// <returns>True if the property is animating, otherwise false.</returns>
public bool IsAnimating(AvaloniaProperty property) public bool IsAnimating(AvaloniaProperty property)
{ {
Contract.Requires<ArgumentNullException>(property != null); property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess(); VerifyAccess();
return _values?.IsAnimating(property) ?? false; return _values?.IsAnimating(property) ?? false;
@ -306,7 +309,8 @@ namespace Avalonia
/// </remarks> /// </remarks>
public bool IsSet(AvaloniaProperty property) public bool IsSet(AvaloniaProperty property)
{ {
Contract.Requires<ArgumentNullException>(property != null); property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess(); VerifyAccess();
return _values?.IsSet(property) ?? false; return _values?.IsSet(property) ?? false;
@ -320,7 +324,7 @@ namespace Avalonia
/// <param name="priority">The priority of the value.</param> /// <param name="priority">The priority of the value.</param>
public void SetValue( public void SetValue(
AvaloniaProperty property, AvaloniaProperty property,
object value, object? value,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property)); property = property ?? throw new ArgumentNullException(nameof(property));
@ -338,7 +342,7 @@ namespace Avalonia
/// <returns> /// <returns>
/// An <see cref="IDisposable"/> if setting the property can be undone, otherwise null. /// An <see cref="IDisposable"/> if setting the property can be undone, otherwise null.
/// </returns> /// </returns>
public IDisposable SetValue<T>( public IDisposable? SetValue<T>(
StyledPropertyBase<T> property, StyledPropertyBase<T> property,
T value, T value,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
@ -497,7 +501,7 @@ namespace Avalonia
} }
/// <inheritdoc/> /// <inheritdoc/>
Delegate[] IAvaloniaObjectDebug.GetPropertyChangedSubscribers() Delegate[]? IAvaloniaObjectDebug.GetPropertyChangedSubscribers()
{ {
return _propertyChanged?.GetInvocationList(); return _propertyChanged?.GetInvocationList();
} }
@ -723,7 +727,8 @@ namespace Avalonia
{ {
var values = o._values; var values = o._values;
if (values?.TryGetValue(property, maxPriority, out value) == true) if (values != null
&& values.TryGetValue(property, maxPriority, out value) == true)
{ {
return value; return value;
} }
@ -873,7 +878,7 @@ namespace Avalonia
} }
else else
{ {
LogBindingError(property, value.Error); LogBindingError(property, value.Error!);
} }
} }
} }
@ -907,14 +912,14 @@ namespace Avalonia
{ {
_owner = owner; _owner = owner;
_property = property; _property = property;
_owner._directBindings.Add(this); _owner._directBindings!.Add(this);
_subscription = source.Subscribe(this); _subscription = source.Subscribe(this);
} }
public void Dispose() public void Dispose()
{ {
_subscription.Dispose(); _subscription.Dispose();
_owner._directBindings.Remove(this); _owner._directBindings!.Remove(this);
} }
public void OnCompleted() => Dispose(); public void OnCompleted() => Dispose();

4
src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs

@ -1,5 +1,7 @@
using System; using System;
#nullable enable
namespace Avalonia.Diagnostics namespace Avalonia.Diagnostics
{ {
/// <summary> /// <summary>
@ -14,6 +16,6 @@ namespace Avalonia.Diagnostics
/// <returns> /// <returns>
/// The subscribers or null if no subscribers. /// The subscribers or null if no subscribers.
/// </returns> /// </returns>
Delegate[] GetPropertyChangedSubscribers(); Delegate[]? GetPropertyChangedSubscribers();
} }
} }

9
src/Avalonia.Base/IAvaloniaObject.cs

@ -1,6 +1,8 @@
using System; using System;
using Avalonia.Data; using Avalonia.Data;
#nullable enable
namespace Avalonia namespace Avalonia
{ {
/// <summary> /// <summary>
@ -11,7 +13,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Raised when a <see cref="AvaloniaProperty"/> value changes on this object. /// Raised when a <see cref="AvaloniaProperty"/> value changes on this object.
/// </summary> /// </summary>
event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged; event EventHandler<AvaloniaPropertyChangedEventArgs>? PropertyChanged;
/// <summary> /// <summary>
/// Clears an <see cref="AvaloniaProperty"/>'s local value. /// Clears an <see cref="AvaloniaProperty"/>'s local value.
@ -75,7 +77,10 @@ namespace Avalonia
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param> /// <param name="priority">The priority of the value.</param>
IDisposable SetValue<T>( /// <returns>
/// An <see cref="IDisposable"/> if setting the property can be undone, otherwise null.
/// </returns>
IDisposable? SetValue<T>(
StyledPropertyBase<T> property, StyledPropertyBase<T> property,
T value, T value,
BindingPriority priority = BindingPriority.LocalValue); BindingPriority priority = BindingPriority.LocalValue);

2
src/Avalonia.Styling/StyledElement.cs

@ -300,7 +300,7 @@ namespace Avalonia
bool IStyleHost.IsStylesInitialized => _styles != null; bool IStyleHost.IsStylesInitialized => _styles != null;
/// <inheritdoc/> /// <inheritdoc/>
IStyleHost? IStyleHost.StylingParent => (IStyleHost)InheritanceParent; IStyleHost? IStyleHost.StylingParent => (IStyleHost?)InheritanceParent;
/// <inheritdoc/> /// <inheritdoc/>
public virtual void BeginInit() public virtual void BeginInit()

4
src/Avalonia.Styling/Styling/PropertySetterInstance.cs

@ -50,7 +50,7 @@ namespace Avalonia.Styling
} }
else else
{ {
_subscription = _target.Bind(_directProperty, this); _subscription = _target.Bind(_directProperty!, this);
} }
} }
else else
@ -100,7 +100,7 @@ namespace Avalonia.Styling
} }
else else
{ {
_target.ClearValue(_directProperty); _target.ClearValue(_directProperty!);
} }
} }

4
src/Avalonia.Styling/Styling/PropertySetterLazyInstance.cs

@ -53,7 +53,7 @@ namespace Avalonia.Styling
} }
else else
{ {
_subscription = _target.Bind(_directProperty, this); _subscription = _target.Bind(_directProperty!, this);
} }
} }
@ -91,7 +91,7 @@ namespace Avalonia.Styling
} }
else else
{ {
_target.ClearValue(_directProperty); _target.ClearValue(_directProperty!);
} }
} }

Loading…
Cancel
Save