Example #1
0
        public static Dictionary <string, KeyValuePair <string, string> > GetDisplayAttr <T>(T pINS)
        {
            Dictionary <string, KeyValuePair <string, string> > result = new Dictionary <string, KeyValuePair <string, string> >();

            PropertyInfo[] piSrc = pINS.GetType().GetProperties();

            for (int i = 0; i < piSrc.Length; i++)
            {
                object objValue = piSrc[i].GetValue(pINS, null);

                foreach (Attribute attr in piSrc[i].GetCustomAttributes(true))
                {
                    DisplayAttr getAttr = attr as DisplayAttr;
                    if (null != getAttr)
                    {
                        string strValue = string.Empty;
                        if (objValue != null)
                        {
                            strValue = objValue.ToString();
                        }
                        result.Add(piSrc[i].Name, new KeyValuePair <string, string>(getAttr.Description, strValue));
                    }
                }
            }
            return(result);
        }
Example #2
0
        public static Dictionary <string, string> GetDisplayAttr <T>()
        {
            Dictionary <string, string> result = new Dictionary <string, string>();
            Type type = typeof(T);

            foreach (PropertyInfo field in type.GetProperties())
            {
                foreach (Attribute attr in field.GetCustomAttributes(true))
                {
                    DisplayAttr getAttr = attr as DisplayAttr;
                    if (null != getAttr)
                    {
                        result.Add(field.Name, getAttr.Description);
                    }
                }
            }

            return(result);
        }