title: Convert Object to NameValueCollection
body: <p>I have to convert a generic object(s) into a NameValueCollection.  I am attempting to use reflection. While I can get the parent properties, I cannot get the properties of a parent property that is an object.</p>
  
  <pre><code>Class One 
  public string name{get;set}
  
  Class Two
  public string desc{get;set}
  public One OneName{get;set;}
  
  public static NameValueCollection GetPropertyName(
          string objType, object objectItem)
  {
      Type type = Type.GetType(objType);
      PropertyInfo[] propertyInfos = type.GetProperties();
      NameValueCollection propNames = new NameValueCollection();
  
      foreach (PropertyInfo propertyInfo in objectItem.GetType().GetProperties())
      {
          if (propertyInfo.CanRead)
          {
              var pName = propertyInfo.Name;
              var pValue = propertyInfo.GetValue(objectItem, null);
              if (pValue != null)
              {
                  propNames.Add(pName, pValue.ToString());
              }
          }
      }
  
      return propNames;
  }
  </code></pre>
  
  <p>I assume there has to be somesort of recursive call but cannot figure out how to do it.  Any help is appreciated.</p>