Search Results for

    Show / Hide Table of Contents
    View Source

    Class ExpressionHelper

    A set of helper methods for dealing with expressions

    Inheritance
    System.Object
    Namespace: Umbraco.Cms.Core
    Assembly: Umbraco.Core.dll
    Syntax
    public static class ExpressionHelper

    Methods

    View Source

    FindProperty(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>
    View Source

    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
    View Source

    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
    View Source

    GetMemberInfo<T, TReturn>(Expression<Func<T, TReturn>>)

    Gets a System.Reflection.MemberInfo from an System.Linq.Expressions.Expression<TDelegate> of provided it refers to member access.

    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 fromExpression cannot be converted to System.Linq.Expressions.MemberExpression.

    Type Parameters
    Name Description
    T
    TReturn

    The type of the return.

    View Source

    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 expression cannot be converted to System.Linq.Expressions.MethodCallExpression.

    View Source

    GetMethodInfo<T>(Expression<Action<T>>)

    Gets a System.Reflection.MethodInfo from an System.Linq.Expressions.Expression<TDelegate> of provided it refers to a method call.

    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 fromExpression is null or cannot be converted to System.Linq.Expressions.MethodCallExpression.

    Type Parameters
    Name Description
    T
    View Source

    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.

    View Source

    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.

    View Source

    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
    View Source

    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.

    View Source

    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.

    View Source

    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
    View Source

    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

    true if the specified expression is constant; otherwise, false.

    View Source

    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

    true if the specified expression is member; otherwise, false.

    View Source

    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

    true if the specified expression is method; otherwise, false.

    View Source

    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

    true if [is method signature equal to] [the specified left]; otherwise, false.

    Remarks

    This is useful for comparing Expression methods that may contain different generic types

    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • FindProperty(LambdaExpression)
      • GetFirstValueFromArguments(IEnumerable<Expression>)
      • GetMember(Expression)
      • GetMemberInfo<T, TReturn>(Expression<Func<T, TReturn>>)
      • GetMethod(Expression)
      • GetMethodInfo<T>(Expression<Action<T>>)
      • GetMethodInfo<TReturn>(Expression<Func<TReturn>>)
      • GetMethodInfo<T1, T2>(Expression<Func<T1, T2>>)
      • GetMethodParams<T1, T2>(Expression<Func<T1, T2>>)
      • GetPropertyInfo<TSource, TProperty>(TSource, Expression<Func<TSource, TProperty>>)
      • GetPropertyInfo<TSource, TProperty>(Expression<Func<TSource, TProperty>>)
      • GetStaticMethodInfo(Delegate)
      • IsConstant(Expression)
      • IsMember(Expression)
      • IsMethod(Expression)
      • IsMethodSignatureEqualTo(MethodInfo, MethodInfo)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX