title: Recursive function of generic type
body: <p>I'm trying to write a recursive function function that takes a class as argument and check all its member to make sure that all members are either type of field or nested type. the function should call itself for taking the nested type members as argument. This is where I fail:</p>
  
  <pre><code>    private void Validate&lt;C&gt;() where C : class
      {
          MemberInfo[] x = typeof(C).GetMembers();
          for (int i = 0; i &lt; x.Length; i++)
          {
              if (x[i].MemberType != MemberTypes.Field &amp;&amp; x[i].MemberType != MemberTypes.NestedType)
              {
                  throw new Exception(string.Format("Class members must be of type Field or NestedType"));
              }
  //here I have problem sending 'a' as argument to the validate function 
        x.Where(a =&gt; a.MemberType == MemberTypes.NestedType).ToList().ForEach(a =&gt; Validate&lt;typeof(a)&gt;());
          }
      } 
  </code></pre>