Пример #1
0
        public static bool Validator(object o)
        {
            PropertyInfo[] infos = o.GetType().GetProperties();
            foreach (PropertyInfo info in infos)
            {
                if (info.PropertyType.Name.Contains("String"))
                {
                    MaxLengthAttr attr = (MaxLengthAttr)info.GetCustomAttribute(typeof(MaxLengthAttr));

                    Type t = info.PropertyType;
                    if (attr != null && attr.MaxLength < ((String)(info.GetValue(o))).Length)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #2
0
        public static int GetLength(PropertyInfo info)
        {
            MaxLengthAttr attr = (MaxLengthAttr)info.GetCustomAttribute(typeof(MaxLengthAttr));

            return(attr.MaxLength);
        }