internal static MatchField Reflect(FieldInfo fieldInfo)
        {
            if (!fieldInfo.IsPublic)
            {
                return(null);
            }
            object[] attrs = fieldInfo.GetCustomAttributes(typeof(MatchAttribute), false);
            if (attrs.Length == 0)
            {
                return(null);
            }
            MatchAttribute attr  = (MatchAttribute)attrs[0];
            MatchField     field = new MatchField();

            field.regex      = new Regex(attr.Pattern, RegexOptions.Singleline | (attr.IgnoreCase ? RegexOptions.IgnoreCase | RegexOptions.CultureInvariant: 0));
            field.group      = attr.Group;
            field.capture    = attr.Capture;
            field.maxRepeats = attr.MaxRepeats;
            field.fieldInfo  = fieldInfo;
            Type fieldType = fieldInfo.FieldType;

            if (field.maxRepeats < 0) // unspecified
            {
                field.maxRepeats = fieldType.IsArray ? int.MaxValue : 1;
            }
            if (fieldType.IsArray)
            {
                fieldType = fieldType.GetElementType();
            }
            if (fieldType != typeof(string))
            {
                field.matchType = MatchType.Reflect(fieldType);
            }
            return(field);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }