Method ParseBindingExpression
ParseBindingExpression<T>(Expression<Func<T>>)
Parses an expression representing access to a nested property and returns two components:
- A lambda expression that evaluates the root object involved in the property chain.
- A string representing the property path relative to that root object (excluding the root itself).
Declaration
public static (Expression<Func<object>> rootExpression, string propertyPath) ParseBindingExpression<T>(Expression<Func<T>> targetProperty)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T>> | targetProperty | An expression representing the property access to be parsed.
For example: |
Returns
Type | Description |
---|---|
(Expression<Func<object>> rootExpression, string propertyPath) | A tuple containing:
|
Type Parameters
Name | Description |
---|---|
T | The type of the final property being accessed in the expression chain. |
Examples
Suppose you have the following object hierarchy:
public class AppModel {
public MouseState Mouse { get; set; }
}
public class MouseState {
public int X { get; set; }
public int Y { get; set; }
}
AppModel DataContext = new AppModel {
Mouse = new MouseState { X = 100, Y = 200 }
};
And you call:
var (rootExpr, path) = ParseExpression(() => DataContext.Mouse.X);
Then:
rootExpr()
will evaluate toDataContext
path
will be"Mouse.X"
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when the expression structure is unsupported, such as:
|