@ -44,11 +44,7 @@ namespace Avalonia.Data
public static readonly BindingNotification UnsetValue =
new BindingNotification ( AvaloniaProperty . UnsetValue ) ;
// Null cannot be held in WeakReference as it's indistinguishable from an expired value so
// use this value in its place.
private static readonly object NullValue = new object ( ) ;
private WeakReference < object > _ value ;
private object _ value ;
/// <summary>
/// Initializes a new instance of the <see cref="BindingNotification"/> class.
@ -56,7 +52,7 @@ namespace Avalonia.Data
/// <param name="value">The binding value.</param>
public BindingNotification ( object value )
{
_ value = new WeakReference < object > ( value ? ? NullValue ) ;
_ value = value ;
}
/// <summary>
@ -73,6 +69,7 @@ namespace Avalonia.Data
Error = error ;
ErrorType = errorType ;
_ value = AvaloniaProperty . UnsetValue ;
}
/// <summary>
@ -84,7 +81,7 @@ namespace Avalonia.Data
public BindingNotification ( Exception error , BindingErrorType errorType , object fallbackValue )
: this ( error , errorType )
{
_ value = new WeakReference < object > ( fallbackValue ? ? NullValue ) ;
_ value = fallbackValue ;
}
/// <summary>
@ -95,31 +92,12 @@ namespace Avalonia.Data
/// If this property is read when <see cref="HasValue"/> is false then it will return
/// <see cref="AvaloniaProperty.UnsetValue"/>.
/// </remarks>
public object Value
{
get
{
if ( _ value ! = null )
{
object result ;
if ( _ value . TryGetTarget ( out result ) )
{
return result = = NullValue ? null : result ;
}
}
// There's the possibility of a race condition in that HasValue can return true,
// and then the value is GC'd before Value is read. We should be ok though as
// we return UnsetValue which should be a safe alternative.
return AvaloniaProperty . UnsetValue ;
}
}
public object Value = > _ value ;
/// <summary>
/// Gets a value indicating whether <see cref="Value"/> should be pushed to the target.
/// </summary>
public bool HasValue = > _ value ! = null ;
public bool HasValue = > _ value ! = AvaloniaProperty . UnsetValue ;
/// <summary>
/// Gets the error that occurred on the source, if any.
@ -256,7 +234,7 @@ namespace Avalonia.Data
/// </summary>
public void SetValue ( object value )
{
_ value = new WeakReference < object > ( value ? ? NullValue ) ;
_ value = value ;
}
/// <inheritdoc/>