/// <summary> /// Gets the name-value pair of a code token using strongly type reflection /// </summary> /// <typeparam name="T">The type of value represents by a code token</typeparam> /// <param name="member">The code token to get the name as expression instance</param> /// <returns>The name-value pair of a code token</returns> public static MemberNameValuePair <T> GetMemberNameValuePair <T>(Expression <Func <T> > member) { var memberExpressionBody = member.Body as MemberExpression; if (memberExpressionBody != null) { return(StrongTypeReflection.GetMemberValueNamePair <T>(memberExpressionBody)); } var unaryExpresionBody = member.Body as UnaryExpression; Guard.AgainstNullReference <StrongTypeReflectionException>(unaryExpresionBody, StrongTypeReflection.METODCALL_ERRORMESSAGE); // ReSharper disable PossibleNullReferenceException var unaryExpressionBodyOperand = unaryExpresionBody.Operand as MemberExpression; Guard.AgainstNullReference <StrongTypeReflectionException>(unaryExpressionBodyOperand, StrongTypeReflection.METODCALL_ERRORMESSAGE); return(StrongTypeReflection.GetMemberValueNamePair <T>(unaryExpressionBodyOperand)); }
/// <summary> /// Gets the System.Reflection.MethodInfo instance for current expression member /// </summary> /// <typeparam name="T1">The type of the first parameter of the method that this delegate encapsulates</typeparam> /// <typeparam name="T2">The type of the second parameter of the method that this delegate encapsulates</typeparam> /// <typeparam name="T3">The type of the third parameter of the method that this delegate encapsulates</typeparam> /// <param name="member">The current axpression member to get System.Reflection.MethodInfo instance from</param> /// <returns>System.Reflection.MethodInfo instance for current expression member</returns> public static MethodInfo Method <T1, T2, T3>(Expression <Action <T1, T2, T3> > member) { return(StrongTypeReflection.GetMemberFromLambdaExpression <MethodInfo>(member)); }
/// <summary> /// Gets the System.Reflection.PropertyField instance for current expression member /// </summary> /// <typeparam name="T">The type of the parameter of the method that this delegate encapsulates</typeparam> /// <param name="member">The current expression member to get System.Reflection.PropertyInfo instance from</param> /// <returns>System.Reflection.PropertyInfo instance for current expression member</returns> public static PropertyInfo Property <T>(Expression <Func <T> > member) { return(StrongTypeReflection.GetMemberFromLambdaExpression <PropertyInfo>(member)); }
/// <summary> /// Gets the name of a code token using strongly type reflection /// </summary> /// <typeparam name="T">The type of value represents by a code token</typeparam> /// <param name="member">The code token to get the name as expression instance</param> /// <returns>The name of a code token</returns> public static string GetMemberName <T>(Expression <Action <T> > member) { return(StrongTypeReflection.GetMemberFromExpression <MemberInfo>(member.Body).Name); }
/// <summary> /// Gets the System.Reflection.FieldInfo instance for current expression member /// </summary> /// <typeparam name="T">The type of the parameter of the method that this delegate encapsulates</typeparam> /// <param name="member">The current expression member to get System.Reflection.FieldInfo instance from</param> /// <returns>System.Reflection.FieldInfo instance for current expression member</returns> public static FieldInfo Field <T>(Expression <Func <T> > member) { return(StrongTypeReflection.GetMemberFromLambdaExpression <FieldInfo>(member)); }