title: How to get generic argument types of generic type from derived type in c#
body: <p>Supose i have:</p>
  
  <pre><code>class MyBase&lt;T1, T2&gt;{}
  
  class MyConcreteBase&lt;T2&gt; : MyBase&lt;ConcreteType1, T2&gt;{}
  
  class MyConcrete1 : MyConcreteBase&lt;ConcreteType2&gt;{}
  
  class MyConcrete2 : MyBase&lt;ConcreteType1, ConcreteType2&gt;{}
  </code></pre>
  
  <p>How do i get types of <code>T1</code> and <code>T2</code> if i have instance of <code>MyConcrete1</code> or <code>MyConcrete2</code> or <code>MyConcreteBase</code> or any other instance of type derived from <code>MyBase&lt;T1, T2&gt;</code></p>
  
  <p>The way i do it now is i'm "getting up" by inheritance chain using <code>.GetType().BaseType</code> while <code>BaseType.Name.StartsWith("MyBase")</code> and then using <code>.GetGenericArguments()</code></p>
  
  <p>It is working, but i'm not satisfied with it, especially <code>.StartsWith("MyBase")</code> part.</p>
  
  <p>Anyone have other suggestions?</p>