Esempio n. 1
0
        private static void ValidateAnonymousTypeMember(ref MemberInfo member, out Type memberType)
        {
            FieldInfo field = member as FieldInfo;

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

            PropertyInfo pi = member as PropertyInfo;

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

            MethodInfo method = member as MethodInfo;

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

                PropertyInfo prop = GetProperty(method);
                member     = prop;
                memberType = prop.PropertyType;
                return;
            }
            throw Error.ArgumentMustBeFieldInfoOrPropertInfoOrMethod();
        }
Esempio n. 2
0
        //CONFORMING
        private static void ValidateAnonymousTypeMember(ref MemberInfo member, out Type memberType)
        {
            switch (member.MemberType)
            {
            case MemberTypes.Field:
                FieldInfo field = member as FieldInfo;
                if (field.IsStatic)
                {
                    throw Error.ArgumentMustBeInstanceMember();
                }
                memberType = field.FieldType;
                break;

            case MemberTypes.Property:
                PropertyInfo pi = member as PropertyInfo;
                if (!pi.CanRead)
                {
                    throw Error.PropertyDoesNotHaveGetter(pi);
                }
                if (pi.GetGetMethod().IsStatic)
                {
                    throw Error.ArgumentMustBeInstanceMember();
                }
                memberType = pi.PropertyType;
                break;

            case MemberTypes.Method:
                MethodInfo method = member as MethodInfo;
                if (method.IsStatic)
                {
                    throw Error.ArgumentMustBeInstanceMember();
                }

                PropertyInfo prop = GetProperty(method);
                member     = prop;
                memberType = prop.PropertyType;
                break;

            default:
                throw Error.ArgumentMustBeFieldInfoOrPropertInfoOrMethod();
            }
        }