|
|
@@ -15,6 +15,7 @@ namespace Perspex.Markup.Binding
|
|
|
public class ExpressionObserver : ObservableBase<ExpressionValue>
|
|
|
{
|
|
|
private int _count;
|
|
|
+ private ExpressionNode _node;
|
|
|
|
|
|
/// <summary>
|
|
|
/// Initializes a new instance of the <see cref="ExpressionObserver"/> class.
|
|
|
@@ -24,7 +25,7 @@ namespace Perspex.Markup.Binding
|
|
|
public ExpressionObserver(object root, string expression)
|
|
|
{
|
|
|
Root = root;
|
|
|
- Nodes = ExpressionNodeBuilder.Build(expression);
|
|
|
+ _node = ExpressionNodeBuilder.Build(expression);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -37,22 +38,16 @@ namespace Perspex.Markup.Binding
|
|
|
/// </returns>
|
|
|
public bool SetValue(object value)
|
|
|
{
|
|
|
- var last = Nodes.Last() as PropertyAccessorNode;
|
|
|
+ IncrementCount();
|
|
|
|
|
|
- if (last != null)
|
|
|
+ try
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- IncrementCount();
|
|
|
- return last.SetValue(value);
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- DecrementCount();
|
|
|
- }
|
|
|
+ return _node.SetValue(value);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ DecrementCount();
|
|
|
}
|
|
|
-
|
|
|
- return false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -60,17 +55,12 @@ namespace Perspex.Markup.Binding
|
|
|
/// </summary>
|
|
|
public object Root { get; }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets a list of nodes representing the parts of the expression.
|
|
|
- /// </summary>
|
|
|
- public IList<ExpressionNode> Nodes { get; }
|
|
|
-
|
|
|
/// <inheritdoc/>
|
|
|
protected override IDisposable SubscribeCore(IObserver<ExpressionValue> observer)
|
|
|
{
|
|
|
IncrementCount();
|
|
|
|
|
|
- var subscription = Nodes[0].Subscribe(observer);
|
|
|
+ var subscription = _node.Subscribe(observer);
|
|
|
|
|
|
return Disposable.Create(() =>
|
|
|
{
|
|
|
@@ -83,7 +73,7 @@ namespace Perspex.Markup.Binding
|
|
|
{
|
|
|
if (_count++ == 0)
|
|
|
{
|
|
|
- Nodes[0].Target = Root;
|
|
|
+ _node.Target = Root;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -91,7 +81,7 @@ namespace Perspex.Markup.Binding
|
|
|
{
|
|
|
if (--_count == 0)
|
|
|
{
|
|
|
- Nodes[0].Target = null;
|
|
|
+ _node.Target = null;
|
|
|
}
|
|
|
}
|
|
|
}
|