Exemplo n.º 1
0
        /// <summary>
        /// ToFriendlyHTMLString (ONLY TO BE USED FOR DEBUGGING PUPOSES PLEASE)!
        /// </summary>
        /// <param name="o"></param>
        /// <returns>Unordered HTML list of properties and values of an object</returns>
        public static string ToFriendlyHTMLString(this IOOObject o)
        {
            StringBuilder       sb           = new StringBuilder("<ul>");
            NameValueCollection nvCollection = GetProperyNameAndValues(o);

            foreach (string key in nvCollection.Keys)
            {
                sb.AppendFormat("<li>{0}: {1}</li>", key, nvCollection[key]);
            }

            sb.Append("</ul>");

            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// GetProperyNameAndValues uses reflection to return a collection of
        /// an objects Simple Type (String or ValueType) properties and values.
        /// </summary>
        /// <param name="o"></param>
        /// <returns>NameValueCollection of an objects properties and associated values</returns>
        public static NameValueCollection GetProperyNameAndValues(this IOOObject o)
        {
            Type objType = o.GetType();

            PropertyInfo[]      fields       = objType.GetProperties();
            NameValueCollection nvCollection = new NameValueCollection();

            foreach (PropertyInfo property in fields)
            {
                if (property.PropertyType == typeof(string) ||
                    property.PropertyType.BaseType == typeof(ValueType))
                {
                    if (property.GetValue(o, null) != null)
                    {
                        nvCollection.Add(property.Name, property.GetValue(o, null).ToString());
                    }
                }
            }

            return(nvCollection);
        }