예제 #1
0
        public static FieldInfo GetField <T>(Expression <Func <T> > fieldExpression)
        {
            Invariant.ArgumentNotNull((object)fieldExpression, "fieldExpression");
            FieldInfo memberInfo = Reflect.GetMemberInfo((LambdaExpression)fieldExpression) as FieldInfo;

            object local = null;

            if (!(memberInfo == (FieldInfo)local))
            {
                return(memberInfo);
            }
            throw new ArgumentException("Expression is not a field access expression.", "memberExpression");
        }
예제 #2
0
        public static MethodInfo GetMethod <T>(Expression <Func <T> > methodExpression)
        {
            Invariant.ArgumentNotNull((object)methodExpression, "methodExpression");
            MethodInfo memberInfo = Reflect.GetMemberInfo((LambdaExpression)methodExpression) as MethodInfo;

            object local = null;

            if (!(memberInfo == (MethodInfo)local))
            {
                return(memberInfo);
            }
            throw new ArgumentException("Expression is not a method call expression.", "memberExpression");
        }
예제 #3
0
        public static PropertyInfo GetProperty <TSource, T>(Expression <Func <TSource, T> > propertyExpression)
        {
            Invariant.ArgumentNotNull((object)propertyExpression, "propertyExpression");
            PropertyInfo memberInfo = Reflect.GetMemberInfo((LambdaExpression)propertyExpression) as PropertyInfo;

            object local = null;

            if (!(memberInfo == (PropertyInfo)local))
            {
                return(memberInfo);
            }
            throw new ArgumentException("Expression is not a property access expression.", "memberExpression");
        }