// PRIVATE METHODS ////////////////////////////////////////////////// #region Methods private static string GetMemberName(Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } var memberExpression = expression as MemberExpression; if (memberExpression != null) { // Reference type property or field return(memberExpression.Member.Name); } var methodCallExpression = expression as MethodCallExpression; if (methodCallExpression != null) { // Reference type method return(methodCallExpression.Method.Name); } var unaryExpression = expression as UnaryExpression; if (unaryExpression != null) { // Property, field of method returning value type return(StaticReflection.GetMemberName(unaryExpression)); } throw new ArgumentException( "Invalid expression, must be either a MemberExpression, MethodCallExpression, or UnaryExpression."); }
public static string GetMemberName <T>(Expression <Action <T> > expression) { if (expression == null) { throw new ArgumentNullException("expression"); } return(StaticReflection.GetMemberName(expression.Body)); }
public static string GetMemberName <T>(this T instance, Expression <Action <T> > expression) { return(StaticReflection.GetMemberName(expression)); }
public static string GetMemberName <T, TProperty>(this T instance, Expression <Func <T, TProperty> > expression) { return(StaticReflection.GetMemberName(expression)); }