public static List <DataCommandParameterAttribute> GetAttributes(Type type) { List <DataCommandParameterAttribute> result = new List <DataCommandParameterAttribute>(); foreach (PropertyInfo p in type.GetProperties()) { foreach (Object oAttrib in p.GetCustomAttributes(true)) { if (oAttrib.GetType() == typeof(DataCommandParameterAttribute)) { DataCommandParameterAttribute att = (DataCommandParameterAttribute)oAttrib; att.PropertyReference = p; DescriptionAttribute _descriptionAttribute = type.GetCustomAttributes(typeof(DescriptionAttribute), true).FirstOrDefault() as DescriptionAttribute; if (_descriptionAttribute != null) { att.Description = _descriptionAttribute.Description; } CategoryAttribute _categoryAttribute = type.GetCustomAttributes(typeof(CategoryAttribute), true).FirstOrDefault() as CategoryAttribute; if (_categoryAttribute != null) { att.Category = _categoryAttribute.Category; } att._name = p.Name; att._isParams = PropertyArrayTypeSupported(p.GetType()); result.Add(att); } } } List <DataCommandParameterAttribute> sorted = (from n in result orderby n.Order ascending select n).ToList(); return(sorted); }
public static DataCommandAttribute GetAttribute(Type type) { foreach (Object oAttrib in type.GetCustomAttributes(true)) { if (oAttrib.GetType() == typeof(DataCommandAttribute)) { DataCommandAttribute fma = (DataCommandAttribute)oAttrib; fma.Parameters = new List <DataCommandParameterAttribute>(); foreach (DataCommandParameterAttribute at in DataCommandParameterAttribute.GetAttributes(type)) { fma.Parameters.Add(at); } if (string.IsNullOrEmpty(fma.Description)) { DescriptionAttribute _attribute = type.GetCustomAttributes(typeof(DescriptionAttribute), true).FirstOrDefault() as DescriptionAttribute; if (_attribute != null) { fma.Description = _attribute.Description; } } if (string.IsNullOrEmpty(fma.Category)) { CategoryAttribute _attribute = type.GetCustomAttributes(typeof(CategoryAttribute), true).FirstOrDefault() as CategoryAttribute; if (_attribute != null) { fma.Category = _attribute.Category; } } return(fma); } } return(null); }