@ -47,18 +47,20 @@ namespace Perspex.Markup.Data
private IDisposable _ updateSubscription ;
private IDisposable _ updateSubscription ;
private int _ count ;
private int _ count ;
private readonly ExpressionNode _ node ;
private readonly ExpressionNode _ node ;
private ValidationMethods _ methods ;
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="ExpressionObserver"/> class.
/// Initializes a new instance of the <see cref="ExpressionObserver"/> class.
/// </summary>
/// </summary>
/// <param name="root">The root object.</param>
/// <param name="root">The root object.</param>
/// <param name="expression">The expression.</param>
/// <param name="expression">The expression.</param>
public ExpressionObserver ( object root , string expression )
/// <param name="methods">The validation methods to enable on this observer.</param>
public ExpressionObserver ( object root , string expression , ValidationMethods methods = ValidationMethods . None )
{
{
Contract . Requires < ArgumentNullException > ( expression ! = null ) ;
Contract . Requires < ArgumentNullException > ( expression ! = null ) ;
_ root = new WeakReference ( root ) ;
_ root = new WeakReference ( root ) ;
_ methods = methods ;
if ( ! string . IsNullOrWhiteSpace ( expression ) )
if ( ! string . IsNullOrWhiteSpace ( expression ) )
{
{
_ node = ExpressionNodeBuilder . Build ( expression ) ;
_ node = ExpressionNodeBuilder . Build ( expression ) ;
@ -72,13 +74,14 @@ namespace Perspex.Markup.Data
/// </summary>
/// </summary>
/// <param name="rootObservable">An observable which provides the root object.</param>
/// <param name="rootObservable">An observable which provides the root object.</param>
/// <param name="expression">The expression.</param>
/// <param name="expression">The expression.</param>
public ExpressionObserver ( IObservable < object > rootObservable , string expression )
/// <param name="methods">The validation methods to enable on this observer.</param>
public ExpressionObserver ( IObservable < object > rootObservable , string expression , ValidationMethods methods = ValidationMethods . None )
{
{
Contract . Requires < ArgumentNullException > ( rootObservable ! = null ) ;
Contract . Requires < ArgumentNullException > ( rootObservable ! = null ) ;
Contract . Requires < ArgumentNullException > ( expression ! = null ) ;
Contract . Requires < ArgumentNullException > ( expression ! = null ) ;
_ rootObservable = rootObservable ;
_ rootObservable = rootObservable ;
_ methods = methods ;
if ( ! string . IsNullOrWhiteSpace ( expression ) )
if ( ! string . IsNullOrWhiteSpace ( expression ) )
{
{
_ node = ExpressionNodeBuilder . Build ( expression ) ;
_ node = ExpressionNodeBuilder . Build ( expression ) ;
@ -93,10 +96,12 @@ namespace Perspex.Markup.Data
/// <param name="rootGetter">A function which gets the root object.</param>
/// <param name="rootGetter">A function which gets the root object.</param>
/// <param name="expression">The expression.</param>
/// <param name="expression">The expression.</param>
/// <param name="update">An observable which triggers a re-read of the getter.</param>
/// <param name="update">An observable which triggers a re-read of the getter.</param>
/// <param name="methods">The validation methods to enable on this observer.</param>
public ExpressionObserver (
public ExpressionObserver (
Func < object > rootGetter ,
Func < object > rootGetter ,
string expression ,
string expression ,
IObservable < Unit > update )
IObservable < Unit > update ,
ValidationMethods methods = ValidationMethods . None )
{
{
Contract . Requires < ArgumentNullException > ( rootGetter ! = null ) ;
Contract . Requires < ArgumentNullException > ( rootGetter ! = null ) ;
Contract . Requires < ArgumentNullException > ( expression ! = null ) ;
Contract . Requires < ArgumentNullException > ( expression ! = null ) ;
@ -104,7 +109,7 @@ namespace Perspex.Markup.Data
_ rootGetter = rootGetter ;
_ rootGetter = rootGetter ;
_ update = update ;
_ update = update ;
_ methods = methods ;
if ( ! string . IsNullOrWhiteSpace ( expression ) )
if ( ! string . IsNullOrWhiteSpace ( expression ) )
{
{
_ node = ExpressionNodeBuilder . Build ( expression ) ;
_ node = ExpressionNodeBuilder . Build ( expression ) ;
@ -216,8 +221,8 @@ namespace Perspex.Markup.Data
{
{
source = source . TakeUntil ( _ update . LastOrDefaultAsync ( ) ) ;
source = source . TakeUntil ( _ update . LastOrDefaultAsync ( ) ) ;
}
}
var validationFiltered = source . Where ( o = > ( o as ValidationStatus ) ? . Match ( _ methods ) ? ? true ) ;
var subscription = source . Subscribe ( observer ) ;
var subscription = validationFiltered . Subscribe ( observer ) ;
return Disposable . Create ( ( ) = >
return Disposable . Create ( ( ) = >
{
{