Esempio n. 1
0
        public static List <FormatMethodParameterAttribute> GetAttributes(Type type)
        {
            List <FormatMethodParameterAttribute> result = new List <FormatMethodParameterAttribute>();

            foreach (PropertyInfo p in type.GetProperties())
            {
                foreach (Object oAttrib in p.GetCustomAttributes(true))
                {
                    if (oAttrib.GetType() == typeof(FormatMethodParameterAttribute))
                    {
                        FormatMethodParameterAttribute att = (FormatMethodParameterAttribute)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 <FormatMethodParameterAttribute> sorted =
                (from n in result
                 orderby n.Order ascending
                 select n).ToList();

            return(sorted);
        }
        public static FormatMethodAttribute GetAttribute(Type type)
        {
            foreach (Object oAttrib in type.GetCustomAttributes(true))
            {
                if (oAttrib.GetType() == typeof(FormatMethodAttribute))
                {
                    FormatMethodAttribute fma = (FormatMethodAttribute)oAttrib;
                    fma.Parameters = new List <FormatMethodParameterAttribute>();
                    foreach (FormatMethodParameterAttribute at in FormatMethodParameterAttribute.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);
        }