|
|
@ -9,16 +9,32 @@ using System.Reactive.Disposables; |
|
|
|
|
|
|
|
|
namespace Perspex.Markup.Binding |
|
|
namespace Perspex.Markup.Binding |
|
|
{ |
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Observes the value of an expression on a root object.
|
|
|
|
|
|
/// </summary>
|
|
|
public class ExpressionObserver : ObservableBase<ExpressionValue> |
|
|
public class ExpressionObserver : ObservableBase<ExpressionValue> |
|
|
{ |
|
|
{ |
|
|
private int _count; |
|
|
private int _count; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="ExpressionObserver"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="root">The root object.</param>
|
|
|
|
|
|
/// <param name="expression">The expression.</param>
|
|
|
public ExpressionObserver(object root, string expression) |
|
|
public ExpressionObserver(object root, string expression) |
|
|
{ |
|
|
{ |
|
|
Root = root; |
|
|
Root = root; |
|
|
Nodes = ExpressionNodeBuilder.Build(expression); |
|
|
Nodes = ExpressionNodeBuilder.Build(expression); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Attempts to set the value of a property expression.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="value">The value to set.</param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// True if the value could be set; false if the expression does not evaluate to a
|
|
|
|
|
|
/// property.
|
|
|
|
|
|
/// </returns>
|
|
|
public bool SetValue(object value) |
|
|
public bool SetValue(object value) |
|
|
{ |
|
|
{ |
|
|
var last = Nodes.Last() as PropertyAccessorNode; |
|
|
var last = Nodes.Last() as PropertyAccessorNode; |
|
|
@ -39,10 +55,17 @@ namespace Perspex.Markup.Binding |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the root object that the expression is being observed on.
|
|
|
|
|
|
/// </summary>
|
|
|
public object Root { get; } |
|
|
public object Root { get; } |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a list of nodes representing the parts of the expression.
|
|
|
|
|
|
/// </summary>
|
|
|
public IList<ExpressionNode> Nodes { get; } |
|
|
public IList<ExpressionNode> Nodes { get; } |
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
protected override IDisposable SubscribeCore(IObserver<ExpressionValue> observer) |
|
|
protected override IDisposable SubscribeCore(IObserver<ExpressionValue> observer) |
|
|
{ |
|
|
{ |
|
|
IncrementCount(); |
|
|
IncrementCount(); |
|
|
|