private static KeyValuePairs AddProperties <TObject>(TObject @object, Int32 nestCounter = 0) where TObject : class { KeyValuePairs result = new KeyValuePairs(); if (@object != null && nestCounter < MaxNesting) { nestCounter++; List <PropertyInfo> properties = @object.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => p != null).ToList(); foreach (PropertyInfo property in properties) { Object valueObject = property.GetValue(@object, null); if (valueObject == null) { continue; } KeyValuePair <String, String> keyValuePair = GetKeyValue(property.Name, valueObject); if (!keyValuePair.Key.IsEmpty()) { result.Add(keyValuePair); } else if (valueObject is IList) { Int32 itemCntr = 0; foreach (Object item in (IList)valueObject) { result.Add(new KeyValuePair <String, String>("{0}[{1}]".FormatX(property.Name, itemCntr++), AddProperties(item, nestCounter).ToString())); } } else { result.Add(new KeyValuePair <String, String>(property.Name, AddProperties(valueObject, nestCounter).ToString())); } } } return(result); }