Example #1
0
        /// <summary>
        /// Converts an object's public properties to a collection of string-based key-value pairs. If the object happens
        /// to be an IDictionary, the IDictionary's keys and values converted to strings and returned.
        /// </summary>
        /// <param name="obj">The object to parse into key-value pairs</param>
        /// <returns></returns>
        public static IEnumerable <KeyValuePair <string, object> > ToKeyValuePairs(this object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            return
                ((obj is string) ? QueryParamCollection.Parse((string)obj) :
                 (obj is IEnumerable) ? CollectionToKV((IEnumerable)obj) :
                 ObjectToKV(obj));
        }