|
@@ -8,9 +8,9 @@ using System.Reactive.Disposables;
|
|
|
using System.Reactive.Linq;
|
|
|
using System.Reactive.Subjects;
|
|
|
using Avalonia.Data;
|
|
|
-using Avalonia.Markup.Data.Plugins;
|
|
|
+using Avalonia.Data.Core.Plugins;
|
|
|
|
|
|
-namespace Avalonia.Markup.Data
|
|
|
+namespace Avalonia.Data.Core
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// Observes and sets the value of an expression on an object.
|
|
@@ -245,40 +245,35 @@ namespace Avalonia.Markup.Data
|
|
|
|
|
|
private object Translate(object o)
|
|
|
{
|
|
|
- var weak = o as WeakReference;
|
|
|
-
|
|
|
- if (weak != null)
|
|
|
+ if (o is WeakReference weak)
|
|
|
{
|
|
|
return weak.Target;
|
|
|
}
|
|
|
- else
|
|
|
+ else if (BindingNotification.ExtractError(o) is MarkupBindingChainException broken)
|
|
|
{
|
|
|
- var broken = BindingNotification.ExtractError(o) as MarkupBindingChainException;
|
|
|
-
|
|
|
- if (broken != null)
|
|
|
- {
|
|
|
- broken.Commit(Description);
|
|
|
- }
|
|
|
- return o;
|
|
|
+ broken.Commit(Description);
|
|
|
}
|
|
|
+
|
|
|
+ return o;
|
|
|
}
|
|
|
|
|
|
private IDisposable StartRoot()
|
|
|
{
|
|
|
- var observable = _root as IObservable<object>;
|
|
|
-
|
|
|
- if (observable != null)
|
|
|
+ switch (_root)
|
|
|
{
|
|
|
- return observable.Subscribe(
|
|
|
- x => _node.Target = new WeakReference(x != AvaloniaProperty.UnsetValue ? x : null),
|
|
|
- _ => _finished.OnNext(Unit.Default),
|
|
|
- () => _finished.OnNext(Unit.Default));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _node.Target = (WeakReference)_root;
|
|
|
- return Disposable.Empty;
|
|
|
+ case IObservable<object> observable:
|
|
|
+ return observable.Subscribe(
|
|
|
+ x => _node.Target = new WeakReference(x != AvaloniaProperty.UnsetValue ? x : null),
|
|
|
+ _ => _finished.OnNext(Unit.Default),
|
|
|
+ () => _finished.OnNext(Unit.Default));
|
|
|
+ case WeakReference weak:
|
|
|
+ _node.Target = weak;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new AvaloniaInternalException("The ExpressionObserver._root member should only be either an observable or WeakReference.");
|
|
|
}
|
|
|
+
|
|
|
+ return Disposable.Empty;
|
|
|
}
|
|
|
}
|
|
|
}
|