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

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

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

9
src/Avalonia.Base/IAvaloniaObject.cs

@ -1,6 +1,8 @@
using System;
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>
@ -11,7 +13,7 @@ namespace Avalonia
/// <summary>
/// Raised when a <see cref="AvaloniaProperty"/> value changes on this object.
/// </summary>
event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
event EventHandler<AvaloniaPropertyChangedEventArgs>? PropertyChanged;
/// <summary>
/// Clears an <see cref="AvaloniaProperty"/>'s local value.
@ -75,7 +77,10 @@ namespace Avalonia
/// <param name="property">The property.</param>
/// <param name="value">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,
T value,
BindingPriority priority = BindingPriority.LocalValue);

2
src/Avalonia.Styling/StyledElement.cs

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

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

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

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

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

Loading…
Cancel
Save