Class ExpressionHelper
A set of helper methods for dealing with expressions
Inheritance
Namespace: Umbraco.Cms.Core
Assembly: Umbraco.Core.dll
Syntax
public static class ExpressionHelper
Methods
View SourceFindProperty(LambdaExpression)
Declaration
public static (MemberInfo, string) FindProperty(LambdaExpression lambda)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.LambdaExpression | lambda |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Reflection.MemberInfo, System.String> |
GetFirstValueFromArguments(IEnumerable<Expression>)
Gets the first value from the supplied arguments of an expression, for those arguments that can be cast to System.Linq.Expressions.ConstantExpression.
Declaration
public static object GetFirstValueFromArguments(IEnumerable<Expression> arguments)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.Linq.Expressions.Expression> | arguments | The arguments. |
Returns
Type | Description |
---|---|
System.Object |
GetMember(Expression)
Gets a System.Reflection.MemberInfo from an System.Linq.Expressions.Expression provided it refers to member access.
Declaration
public static MemberInfo GetMember(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | The expression. |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo |
GetMemberInfo<T, TReturn>(Expression<Func<T, TReturn>>)
Gets a System.Reflection.MemberInfo from an System.Linq.Expressions.Expression<TDelegate> of
Declaration
public static MemberInfo GetMemberInfo<T, TReturn>(Expression<Func<T, TReturn>> fromExpression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<Func<T, TReturn>> | fromExpression | From expression. |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo | The System.Reflection.MemberInfo or null if |
Type Parameters
Name | Description |
---|---|
T | |
TReturn | The type of the return. |
GetMethod(Expression)
Gets a System.Reflection.MethodInfo from an System.Linq.Expressions.Expression provided it refers to a method call.
Declaration
public static MethodInfo GetMethod(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | The expression. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo | The System.Reflection.MethodInfo or null if |
GetMethodInfo<T>(Expression<Action<T>>)
Gets a System.Reflection.MethodInfo from an System.Linq.Expressions.Expression<TDelegate> of
Declaration
public static MethodInfo GetMethodInfo<T>(Expression<Action<T>> fromExpression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<Action<T>> | fromExpression | From expression. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo | The System.Reflection.MethodInfo or null if |
Type Parameters
Name | Description |
---|---|
T |
GetMethodInfo<TReturn>(Expression<Func<TReturn>>)
Gets the method info.
Declaration
public static MethodInfo GetMethodInfo<TReturn>(Expression<Func<TReturn>> fromExpression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<Func<TReturn>> | fromExpression | From expression. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo |
Type Parameters
Name | Description |
---|---|
TReturn | The return type of the method. |
GetMethodInfo<T1, T2>(Expression<Func<T1, T2>>)
Gets the method info.
Declaration
public static MethodInfo GetMethodInfo<T1, T2>(Expression<Func<T1, T2>> fromExpression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<Func<T1, T2>> | fromExpression | From expression. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo |
Type Parameters
Name | Description |
---|---|
T1 | The type of the 1. |
T2 | The type of the 2. |
GetMethodParams<T1, T2>(Expression<Func<T1, T2>>)
Declaration
public static IDictionary<string, object>? GetMethodParams<T1, T2>(Expression<Func<T1, T2>> fromExpression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<Func<T1, T2>> | fromExpression |
Returns
Type | Description |
---|---|
System.Nullable<IDictionary<System.String, System.Object>> |
Type Parameters
Name | Description |
---|---|
T1 | |
T2 |
GetPropertyInfo<TSource, TProperty>(TSource, Expression<Func<TSource, TProperty>>)
Gets a System.Reflection.PropertyInfo object from an expression.
Declaration
public static PropertyInfo GetPropertyInfo<TSource, TProperty>(this TSource source, Expression<Func<TSource, TProperty>> propertyLambda)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source. |
System.Linq.Expressions.Expression<Func<TSource, TProperty>> | propertyLambda | The property lambda. |
Returns
Type | Description |
---|---|
System.Reflection.PropertyInfo |
Type Parameters
Name | Description |
---|---|
TSource | The type of the source. |
TProperty | The type of the property. |
GetPropertyInfo<TSource, TProperty>(Expression<Func<TSource, TProperty>>)
Gets a System.Reflection.PropertyInfo object from an expression.
Declaration
public static PropertyInfo GetPropertyInfo<TSource, TProperty>(Expression<Func<TSource, TProperty>> propertyLambda)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<Func<TSource, TProperty>> | propertyLambda | The property lambda. |
Returns
Type | Description |
---|---|
System.Reflection.PropertyInfo |
Type Parameters
Name | Description |
---|---|
TSource | The type of the source. |
TProperty | The type of the property. |
GetStaticMethodInfo(Delegate)
Gets a System.Reflection.MethodInfo from a
Declaration
public static MethodInfo GetStaticMethodInfo(Delegate fromMethodGroup)
Parameters
Type | Name | Description |
---|---|---|
Delegate | fromMethodGroup | From method group. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo |
IsConstant(Expression)
Determines whether the specified expression is a constant.
Declaration
public static bool IsConstant(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | The expression. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsMember(Expression)
Determines whether the specified expression is a member.
Declaration
public static bool IsMember(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | The expression. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsMethod(Expression)
Determines whether the specified expression is a method.
Declaration
public static bool IsMethod(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | The expression. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsMethodSignatureEqualTo(MethodInfo, MethodInfo)
Determines whether the MethodInfo is the same based on signature, not based on the equality operator or HashCode.
Declaration
public static bool IsMethodSignatureEqualTo(this MethodInfo left, MethodInfo right)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | left | The left. |
System.Reflection.MethodInfo | right | The right. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
This is useful for comparing Expression methods that may contain different generic types