diff --git a/src/Avalonia.Base/Data/Core/ExpressionObserver.cs b/src/Avalonia.Base/Data/Core/ExpressionObserver.cs
index 07e01498e5..773049d3a5 100644
--- a/src/Avalonia.Base/Data/Core/ExpressionObserver.cs
+++ b/src/Avalonia.Base/Data/Core/ExpressionObserver.cs
@@ -82,24 +82,6 @@ namespace Avalonia.Data.Core
_root = new WeakReference(root);
}
- ///
- /// Creates a new instance of the class.
- ///
- /// The root object.
- /// The expression.
- /// Whether or not to track data validation
- ///
- /// A description of the expression. If null, 's string representation will be used.
- ///
- public static ExpressionObserver Create(
- T root,
- Expression> expression,
- bool enableDataValidation = false,
- string description = null)
- {
- return new ExpressionObserver(root, Parse(expression, enableDataValidation), description ?? expression.ToString());
- }
-
///
/// Initializes a new instance of the class.
///
@@ -119,29 +101,6 @@ namespace Avalonia.Data.Core
Description = description;
_root = rootObservable;
}
-
- ///
- /// Creates a new instance of the class.
- ///
- /// An observable which provides the root object.
- /// The expression.
- /// Whether or not to track data validation
- ///
- /// A description of the expression. If null, 's string representation will be used.
- ///
- public static ExpressionObserver Create(
- IObservable rootObservable,
- Expression> expression,
- bool enableDataValidation = false,
- string description = null)
- {
- Contract.Requires(rootObservable != null);
- return new ExpressionObserver(
- rootObservable.Select(o => (object)o),
- Parse(expression, enableDataValidation),
- description ?? expression.ToString());
-
- }
///
/// Initializes a new instance of the class.
@@ -166,6 +125,47 @@ namespace Avalonia.Data.Core
_root = update.Select(x => rootGetter());
}
+
+ ///
+ /// Creates a new instance of the class.
+ ///
+ /// The root object.
+ /// The expression.
+ /// Whether or not to track data validation
+ ///
+ /// A description of the expression. If null, 's string representation will be used.
+ ///
+ public static ExpressionObserver Create(
+ T root,
+ Expression> expression,
+ bool enableDataValidation = false,
+ string description = null)
+ {
+ return new ExpressionObserver(root, Parse(expression, enableDataValidation), description ?? expression.ToString());
+ }
+
+ ///
+ /// Creates a new instance of the class.
+ ///
+ /// An observable which provides the root object.
+ /// The expression.
+ /// Whether or not to track data validation
+ ///
+ /// A description of the expression. If null, 's string representation will be used.
+ ///
+ public static ExpressionObserver Create(
+ IObservable rootObservable,
+ Expression> expression,
+ bool enableDataValidation = false,
+ string description = null)
+ {
+ Contract.Requires(rootObservable != null);
+ return new ExpressionObserver(
+ rootObservable.Select(o => (object)o),
+ Parse(expression, enableDataValidation),
+ description ?? expression.ToString());
+ }
+
///
/// Creates a new instance of the class.
///
@@ -278,8 +278,7 @@ namespace Avalonia.Data.Core
private static ExpressionNode Parse(LambdaExpression expression, bool enableDataValidation)
{
- var parser = new ExpressionTreeParser(enableDataValidation);
- return parser.Parse(expression);
+ return ExpressionTreeParser.Parse(expression, enableDataValidation);
}
private void StartRoot()
diff --git a/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs b/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs
index 0b0d43a97d..04412b61ef 100644
--- a/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs
+++ b/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs
@@ -10,35 +10,35 @@ namespace Avalonia.Data.Core
{
class IndexerExpressionNode : IndexerNodeBase
{
- private readonly ParameterExpression parameter;
- private readonly IndexExpression expression;
- private readonly Delegate setDelegate;
- private readonly Delegate getDelegate;
- private readonly Delegate firstArgumentDelegate;
+ private readonly ParameterExpression _parameter;
+ private readonly IndexExpression _expression;
+ private readonly Delegate _setDelegate;
+ private readonly Delegate _getDelegate;
+ private readonly Delegate _firstArgumentDelegate;
public IndexerExpressionNode(IndexExpression expression)
{
- parameter = Expression.Parameter(expression.Object.Type);
- this.expression = expression.Update(parameter, expression.Arguments);
+ _parameter = Expression.Parameter(expression.Object.Type);
+ _expression = expression.Update(_parameter, expression.Arguments);
- getDelegate = Expression.Lambda(this.expression, parameter).Compile();
+ _getDelegate = Expression.Lambda(_expression, _parameter).Compile();
var valueParameter = Expression.Parameter(expression.Type);
- setDelegate = Expression.Lambda(Expression.Assign(this.expression, valueParameter), parameter, valueParameter).Compile();
+ _setDelegate = Expression.Lambda(Expression.Assign(_expression, valueParameter), _parameter, valueParameter).Compile();
- firstArgumentDelegate = Expression.Lambda(this.expression.Arguments[0], parameter).Compile();
+ _firstArgumentDelegate = Expression.Lambda(_expression.Arguments[0], _parameter).Compile();
}
- public override Type PropertyType => expression.Type;
+ public override Type PropertyType => _expression.Type;
- public override string Description => expression.ToString();
+ public override string Description => _expression.ToString();
protected override bool SetTargetValueCore(object value, BindingPriority priority)
{
try
{
- setDelegate.DynamicInvoke(Target.Target, value);
+ _setDelegate.DynamicInvoke(Target.Target, value);
return true;
}
catch (Exception)
@@ -51,7 +51,7 @@ namespace Avalonia.Data.Core
{
try
{
- return getDelegate.DynamicInvoke(target);
+ return _getDelegate.DynamicInvoke(target);
}
catch (TargetInvocationException e) when (e.InnerException is ArgumentOutOfRangeException
|| e.InnerException is IndexOutOfRangeException
@@ -63,9 +63,9 @@ namespace Avalonia.Data.Core
protected override bool ShouldUpdate(object sender, PropertyChangedEventArgs e)
{
- return expression.Indexer == null || expression.Indexer.Name == e.PropertyName;
+ return _expression.Indexer == null || _expression.Indexer.Name == e.PropertyName;
}
- protected override int? TryGetFirstArgumentAsInt() => firstArgumentDelegate.DynamicInvoke(Target.Target) as int?;
+ protected override int? TryGetFirstArgumentAsInt() => _firstArgumentDelegate.DynamicInvoke(Target.Target) as int?;
}
}
diff --git a/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs b/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs
index 4d6f56667a..db5d117687 100644
--- a/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs
+++ b/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs
@@ -6,16 +6,9 @@ using System.Text;
namespace Avalonia.Data.Core.Parsers
{
- class ExpressionTreeParser
+ static class ExpressionTreeParser
{
- private readonly bool enableDataValidation;
-
- public ExpressionTreeParser(bool enableDataValidation)
- {
- this.enableDataValidation = enableDataValidation;
- }
-
- public ExpressionNode Parse(Expression expr)
+ public static ExpressionNode Parse(Expression expr, bool enableDataValidation)
{
var visitor = new ExpressionVisitorNodeBuilder(enableDataValidation);
diff --git a/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs b/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs
index dba9078423..1b4d1c200d 100644
--- a/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs
+++ b/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs
@@ -14,7 +14,7 @@ namespace Avalonia.Data.Core.Parsers
private static PropertyInfo AvaloniaObjectIndexer;
private static MethodInfo CreateDelegateMethod;
- private readonly bool enableDataValidation;
+ private readonly bool _enableDataValidation;
static ExpressionVisitorNodeBuilder()
{
@@ -26,7 +26,7 @@ namespace Avalonia.Data.Core.Parsers
public ExpressionVisitorNodeBuilder(bool enableDataValidation)
{
- this.enableDataValidation = enableDataValidation;
+ _enableDataValidation = enableDataValidation;
Nodes = new List();
}
@@ -62,7 +62,7 @@ namespace Avalonia.Data.Core.Parsers
protected override Expression VisitMember(MemberExpression node)
{
var visited = base.VisitMember(node);
- Nodes.Add(new PropertyAccessorNode(node.Member.Name, enableDataValidation));
+ Nodes.Add(new PropertyAccessorNode(node.Member.Name, _enableDataValidation));
return visited;
}
@@ -73,7 +73,7 @@ namespace Avalonia.Data.Core.Parsers
if (node.Indexer == AvaloniaObjectIndexer)
{
var property = GetArgumentExpressionValue(node.Arguments[0]);
- Nodes.Add(new AvaloniaPropertyAccessorNode(property, enableDataValidation));
+ Nodes.Add(new AvaloniaPropertyAccessorNode(property, _enableDataValidation));
}
else
{
@@ -164,7 +164,7 @@ namespace Avalonia.Data.Core.Parsers
if (node.Method == CreateDelegateMethod)
{
var visited = Visit(node.Arguments[1]);
- Nodes.Add(new PropertyAccessorNode(GetArgumentExpressionValue(node.Object).Name, enableDataValidation));
+ Nodes.Add(new PropertyAccessorNode(GetArgumentExpressionValue(node.Object).Name, _enableDataValidation));
return node;
}
else if (node.Method.Name == StreamBindingExtensions.StreamBindingName || node.Method.Name.StartsWith(StreamBindingExtensions.StreamBindingName + '`'))