title: Retrieving the PropertyDescriptor of a nested object
body: <p>I have the following code:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
          object o;
          Person p = new Person { FirstName = "John", Surname = "Henry" };
          Citizen c = new Citizen { Country = "Canada", ResidentName = p };
          SportsFan sf = new SportsFan { Sport = "Hockey", Fan = c };
  
          Discoverer&lt;SportsFan&gt;.SimpleExample("Sport", "Hockey",out o);
          Discoverer&lt;SportsFan&gt;.NestedProperyExample("Fan.Citizen.FirstName", "John",out o);
      }
  
      private class Person
      {
          public string FirstName
          {
              get; set;
          }
  
          public string Surname
          {
              get; set;
          }
      }
  
      private class Citizen
      {
          public Person ResidentName
          {
              get; set;
          }
  
          public string Country
          {
              get; set;
          }
      }
  
      private class SportsFan
      {
          public string Sport
          {
              get; set;
          }
  
          public Citizen Fan
          {
              get; set;
          }
      }
  
      private class Discoverer&lt;T&gt;
      {
          public static void SimpleExample(string propName, string objResultToString,out Object obj)
          {
              PropertyDescriptor propDesc;
              propDesc = TypeDescriptor.GetProperties(typeof(T))[propName];               
  
              TypeConverter converter = TypeDescriptor.GetConverter(propDesc.PropertyType);
              obj = converter.ConvertFromString(objResultToString);                   
          }
  
          public static void NestedProperyExample(string propName, string objResultToString, out Object obj)
          {
              PropertyDescriptor propDesc = null;
              obj = null;
              string[] nestedProperties = propName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
  
              propDesc = TypeDescriptor.GetProperties("Form1." + nestedProperties[0])[nestedProperties[1]];
              for (int i = 1; i &lt; nestedProperties.Length - 1; i++)
              {
                  if (propDesc != null)
                      propDesc = TypeDescriptor.GetProperties(propDesc.GetType())[nestedProperties[i + 1]];
              }
  
              if (propDesc != null)
              {
                  TypeConverter converter = TypeDescriptor.GetConverter(propDesc.PropertyType);
                  obj = converter.ConvertFromString(objResultToString);
              }
  
          }
      }
  
  
  }
  </code></pre>
  
  <p>The code works for the <code>simpleExample</code>.  On the <code>NestedPropertyExample</code>, the first assignment to <code>PropDesc</code> returns <code>null</code>.  When I check <code>TypeDescriptor.GetProperties("Form1." + nestedProperties[0])</code>, it returns a <code>PropertyDescriptorCollection</code> of one item and that is Length.</p>
  
  <p>Why am I not returning more <code>PropertyDesriptor</code> items?  Am I going about this the correct way?</p>
  
  <p>Thanks, Bill N</p>