ArgumentMustBeFieldInfoOrPropertyInfoOrMethod() static private method

ArgumentException with message like "Argument must be either a FieldInfo, PropertyInfo or MethodInfo"
static private ArgumentMustBeFieldInfoOrPropertyInfoOrMethod ( string paramName ) : Exception
paramName string
return System.Exception
Esempio n. 1
0
        private static void ValidateAnonymousTypeMember(ref MemberInfo member, out Type memberType, string paramName, int index)
        {
            FieldInfo field = member as FieldInfo;

            if (field != null)
            {
                if (field.IsStatic)
                {
                    throw Error.ArgumentMustBeInstanceMember(paramName, index);
                }
                memberType = field.FieldType;
                return;
            }

            PropertyInfo pi = member as PropertyInfo;

            if (pi != null)
            {
                if (!pi.CanRead)
                {
                    throw Error.PropertyDoesNotHaveGetter(pi, paramName, index);
                }
                if (pi.GetGetMethod().IsStatic)
                {
                    throw Error.ArgumentMustBeInstanceMember(paramName, index);
                }
                memberType = pi.PropertyType;
                return;
            }

            MethodInfo method = member as MethodInfo;

            if (method != null)
            {
                if (method.IsStatic)
                {
                    throw Error.ArgumentMustBeInstanceMember(paramName, index);
                }

                PropertyInfo prop = GetProperty(method, paramName, index);
                member     = prop;
                memberType = prop.PropertyType;
                return;
            }
            throw Error.ArgumentMustBeFieldInfoOrPropertyInfoOrMethod(paramName, index);
        }