Class PropertySignature
A property path such as "Customer.Address.City", resolved against a starting type into the chain of PropertyInfo it names, and buildable into the LINQ expression that reads it.
public class PropertySignature
- Inheritance
-
PropertySignature
- Inherited Members
Remarks
Query clauses - where, orderBy, select, expand - all address properties by path, so each of them resolves its paths through this class. Resolution happens in the constructor, so an instance that was constructed successfully always holds a valid chain.
Constructors
PropertySignature(Type, string)
Resolve a property path against a type.
public PropertySignature(Type instanceType, string propertyPath)
Parameters
instanceTypeTypeThe type the path starts from.
propertyPathstringA property name, or several joined with '.' to walk into related types.
Exceptions
- Exception
A segment of the path does not name a public instance property or field of the type it is applied to.
Properties
ElementType
For a path ending in a collection, the type of its items; null for a scalar property.
public Type? ElementType { get; }
Property Value
InstanceType
The type the path starts from.
public Type InstanceType { get; }
Property Value
IsDataProperty
Whether the path ends in a value - a predefined type or an enum - rather than in another entity.
public bool IsDataProperty { get; }
Property Value
IsNavigationProperty
Whether the path ends in another entity, or a collection of them, rather than in a value.
public bool IsNavigationProperty { get; }
Property Value
Name
The path with its segments joined by '_', giving a name usable as an identifier - "Customer_Address_City".
public string Name { get; }
Property Value
Properties
The resolved chain, one entry per segment of the path.
public List<PropertyInfo> Properties { get; }
Property Value
PropertyPath
The path as it was written, e.g. "Customer.Address.City".
public string PropertyPath { get; }
Property Value
ReturnType
The type of the last property in the chain - what reading the path yields.
public Type ReturnType { get; }
Property Value
Methods
BuildMemberExpression(ParameterExpression)
Build the expression that reads this path off a parameter - for the path "Address.City" and parameter x, the expression x.Address.City.
public Expression BuildMemberExpression(ParameterExpression parmExpr)
Parameters
parmExprParameterExpressionThe parameter the path is read from, typically the lambda parameter of the query.
Returns
- Expression
The member access expression.
BuildPropertyExpression(Expression, PropertyInfo)
Build a single property access - one step of the chain that BuildMemberExpression(ParameterExpression) assembles.
public Expression BuildPropertyExpression(Expression baseExpr, PropertyInfo property)
Parameters
baseExprExpressionThe expression the property is read from.
propertyPropertyInfoThe property to read.
Returns
- Expression
The member access expression.
GetProperties(Type, string, bool)
Walk a property path, yielding the property behind each segment.
public static IEnumerable<PropertyInfo> GetProperties(Type instanceType, string propertyPath, bool throwOnError = true)
Parameters
instanceTypeTypeThe type the path starts from.
propertyPathstringA property name, or several joined with '.'.
throwOnErrorboolWhen true an unresolvable segment throws; when false the walk stops there, yielding only the segments that did resolve.
Returns
- IEnumerable<PropertyInfo>
The properties named by the path, in order.
Exceptions
- Exception
A segment does not resolve and
throwOnErroris true.
IsProperty(Type, string)
Whether a property path resolves against a type, without throwing if it does not.
public static bool IsProperty(Type instanceType, string propertyPath)
Parameters
Returns
- bool
True if the path resolves.