How to get the list of properties of a class?

 public List<string> GetPropertiesNameFromClass(object pObject)
        {
            List<string> propertyList = new List<string>();
            if (pObject != null)
            {
                foreach (var prop in pObject.GetType().GetProperties())
                {
                    propertyList.Add(prop.Name);
                }
            }
            return propertyList;
        }

public static Dictionary<string, object> GetPropertDictionaryFromClass(object pObject)
        {
            if (pObject == null) return new Dictionary<string, object>();
            Type t = pObject.GetType();
            PropertyInfo[] props = t.GetProperties();
            Dictionary<string, object> dict = new Dictionary<string, object>();
            foreach (PropertyInfo prp in props)
            {
                object value = prp.GetValue(pObject, new object[] { });
                dict.Add(prp.Name, value);
            }
            return dict;
        }

Comments