title: Recursive call on generic method with new type from PropertyInfo?
body: <p>I have a customer class with a sub-class address</p>
  
  <pre><code>internal class Customer    
  {
      public int id { get; set; }
      public string name { get; set; }
  
      [ObjectDefRelation(isSubClass = true)]
      public Addressinformation Addressinformation { get; set; }
  }
  
  internal class Addressinformation 
  {
      public string street { get; set; }
  }
  </code></pre>
  
  <p>I have a Method to fill this object with data from a xml. Now I want to call this method recursive when its arrive the sub-class <code>Addressinformation</code>. How can I call my generic method with informations from <code>PropertyInfo</code>?</p>
  
  <pre><code>public static T ConvertXmlToClass&lt;T&gt;(XmlDocument xmlDocumentObjectDef, XmlNode xmlNode, ObjectDefRelationAttribute parentClass = null) where T : new()
  {
      ObjectDefRelationAttribute defRelationAttribute;
      T xmlToClass = new T();
  
      foreach (PropertyInfo field in xmlToClass.GetType().GetProperties())
      {
          foreach (Attribute attr in field.GetCustomAttributes(true))
          {
              defRelationAttribute = attr as ObjectDefRelationAttribute;
              if (null != defRelationAttribute)
              {
                  if (defRelationAttribute.isSubClass)
                  {
                      // 
                      // here I need help to call the recursive method (XXX)
                      //
                      var subClass = Helper.ConvertXmlToClass&lt;XXX&gt;(xmlDocumentObjectDef, xmlNode, defRelationAttribute);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I used the best answer with some modification:</p>
  
  <pre><code>Type typeArguments = GetType(field.PropertyType.Namespace + "." + field.PropertyType.Name);
  object value = typeof(Helper).GetMethod("ConvertXmlToClass").MakeGenericMethod(typeArguments).Invoke(null, new object[] {xmlDocumentObjectDef, xmlNode, defRelationAttribute});
  </code></pre>