internal static MatchType Reflect(System.Type type)
        {
            MatchType type2 = new MatchType {
                type = type
            };

            MemberInfo[] members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            ArrayList    list    = new ArrayList();

            for (int i = 0; i < members.Length; i++)
            {
                MatchMember member = MatchMember.Reflect(members[i]);
                if (member != null)
                {
                    list.Add(member);
                }
            }
            type2.fields = (MatchMember[])list.ToArray(typeof(MatchMember));
            return(type2);
        }
Ejemplo n.º 2
0
        internal static MatchType Reflect(Type type)
        {
            MatchType matchType = new MatchType();

            matchType.type = type;

            MemberInfo[] memberInfos = type.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
            ArrayList    list        = new ArrayList();

            for (int i = 0; i < memberInfos.Length; i++)
            {
                MatchMember member = MatchMember.Reflect(memberInfos[i]);
                if (member != null)
                {
                    list.Add(member);
                }
            }
            matchType.fields = (MatchMember[])list.ToArray(typeof(MatchMember));
            return(matchType);
        }
Ejemplo n.º 3
0
        internal static MatchMember Reflect(MemberInfo memberInfo)
        {
            Type propertyType = null;

            if (memberInfo is PropertyInfo)
            {
                PropertyInfo info = (PropertyInfo)memberInfo;
                if (!info.CanRead)
                {
                    return(null);
                }
                if (!info.CanWrite)
                {
                    return(null);
                }
                MethodInfo getMethod = info.GetGetMethod();
                if (getMethod.IsStatic)
                {
                    return(null);
                }
                if (getMethod.GetParameters().Length > 0)
                {
                    return(null);
                }
                propertyType = info.PropertyType;
            }
            if (memberInfo is FieldInfo)
            {
                FieldInfo info3 = (FieldInfo)memberInfo;
                if (!info3.IsPublic)
                {
                    return(null);
                }
                if (info3.IsStatic)
                {
                    return(null);
                }
                if (info3.IsSpecialName)
                {
                    return(null);
                }
                propertyType = info3.FieldType;
            }
            object[] customAttributes = memberInfo.GetCustomAttributes(typeof(MatchAttribute), false);
            if (customAttributes.Length == 0)
            {
                return(null);
            }
            MatchAttribute attribute = (MatchAttribute)customAttributes[0];
            MatchMember    member    = new MatchMember {
                regex      = new Regex(attribute.Pattern, RegexOptions.Singleline | (attribute.IgnoreCase ? (RegexOptions.CultureInvariant | RegexOptions.IgnoreCase) : RegexOptions.None)),
                group      = attribute.Group,
                capture    = attribute.Capture,
                maxRepeats = attribute.MaxRepeats,
                memberInfo = memberInfo
            };

            if (member.maxRepeats < 0)
            {
                member.maxRepeats = propertyType.IsArray ? 0x7fffffff : 1;
            }
            if (propertyType.IsArray)
            {
                propertyType = propertyType.GetElementType();
            }
            if (propertyType != typeof(string))
            {
                member.matchType = MatchType.Reflect(propertyType);
            }
            return(member);
        }
Ejemplo n.º 4
0
        internal static MatchMember Reflect(MemberInfo memberInfo)
        {
            Type memberType = null;

            if (memberInfo is PropertyInfo)
            {
                PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
                if (!propertyInfo.CanRead)
                {
                    return(null);
                }
                //
                if (!propertyInfo.CanWrite)
                {
                    return(null);
                }

                MethodInfo getMethod = propertyInfo.GetGetMethod();
                if (getMethod.IsStatic)
                {
                    return(null);
                }
                ParameterInfo[] parameters = getMethod.GetParameters();
                if (parameters.Length > 0)
                {
                    return(null);
                }
                memberType = propertyInfo.PropertyType;
            }
            if (memberInfo is FieldInfo)
            {
                FieldInfo fieldInfo = (FieldInfo)memberInfo;
                if (!fieldInfo.IsPublic)
                {
                    return(null);
                }
                if (fieldInfo.IsStatic)
                {
                    return(null);
                }
                if (fieldInfo.IsSpecialName)
                {
                    return(null);
                }
                memberType = fieldInfo.FieldType;
            }
            object[] attrs = memberInfo.GetCustomAttributes(typeof(MatchAttribute), false);
            if (attrs.Length == 0)
            {
                return(null);
            }
            MatchAttribute attr   = (MatchAttribute)attrs[0];
            MatchMember    member = new MatchMember();

            member.regex      = new Regex(attr.Pattern, RegexOptions.Singleline | (attr.IgnoreCase ? RegexOptions.IgnoreCase | RegexOptions.CultureInvariant : 0));
            member.group      = attr.Group;
            member.capture    = attr.Capture;
            member.maxRepeats = attr.MaxRepeats;
            member.memberInfo = memberInfo;

            if (member.maxRepeats < 0) // unspecified
            {
                member.maxRepeats = memberType.IsArray ? int.MaxValue : 1;
            }
            if (memberType.IsArray)
            {
                memberType = memberType.GetElementType();
            }
            if (memberType != typeof(string))
            {
                member.matchType = MatchType.Reflect(memberType);
            }
            return(member);
        }
Ejemplo n.º 5
0
 internal static MatchMember Reflect(MemberInfo memberInfo) {
     Type memberType = null;
     if (memberInfo is PropertyInfo) {
         PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
         if (!propertyInfo.CanRead)
             return null;
         // 
         if (!propertyInfo.CanWrite)
             return null;
         
         MethodInfo getMethod = propertyInfo.GetGetMethod();
         if (getMethod.IsStatic) 
             return null;
         ParameterInfo[] parameters = getMethod.GetParameters();
         if (parameters.Length > 0) 
             return null;
         memberType = propertyInfo.PropertyType;
     }
     if (memberInfo is FieldInfo) {
         FieldInfo fieldInfo = (FieldInfo)memberInfo;
         if (!fieldInfo.IsPublic) 
             return null;
         if (fieldInfo.IsStatic)
             return null;
         if (fieldInfo.IsSpecialName) 
             return null;
         memberType = fieldInfo.FieldType;
     }
     object[] attrs = memberInfo.GetCustomAttributes(typeof(MatchAttribute), false);
     if (attrs.Length == 0) return null;
     MatchAttribute attr = (MatchAttribute)attrs[0];
     MatchMember member = new MatchMember();
     member.regex = new Regex(attr.Pattern, RegexOptions.Singleline | (attr.IgnoreCase ? RegexOptions.IgnoreCase | RegexOptions.CultureInvariant : 0));
     member.group = attr.Group;
     member.capture = attr.Capture;
     member.maxRepeats = attr.MaxRepeats;
     member.memberInfo = memberInfo;
     
     if (member.maxRepeats < 0) // unspecified
         member.maxRepeats = memberType.IsArray ? int.MaxValue : 1;
     if (memberType.IsArray) {
         memberType = memberType.GetElementType();
     }
     if (memberType != typeof(string)) {
         member.matchType = MatchType.Reflect(memberType);
     }
     return member;
 }