title: Generics: cast derived class back to it's parent super class
body: <p>I have three base classes:</p>
  <pre><code>public class ItemBase
  {
      public string Name { get; set; }
  }
  
  public class ProductBase&lt;T&gt; : ItemBase
      where T : ItemBase
  {
      public List&lt;T&gt; Modifiers { get; set; }
      public List&lt;T&gt; GroupModifiers { get; set; }
  }
  
  public class ModifierBase&lt;T&gt; : ItemBase
      where T : ItemBase
  {
      public List&lt;T&gt; ChildModifiers { get; set; }
  }
  </code></pre>
  <p>And two derived classes:</p>
  <pre><code>public class Product : ProductBase&lt;Modifier&gt;
  {
      public string Some_Product_Specific_Property { get; set; }
  }
  
  public class Modifier : ModifierBase&lt;Modifier&gt;
  {
      public string Some_Modifier_Specific_Property { get; set; }
  }
  </code></pre>
  <p>The intent behind all this is to have different sets of derived classes like <code>Product</code> and <code>ProductFromOtherSystem</code> each with it's own specific properties but with the same basic properties.</p>
  <p>And now I need to process basic properties of any class derived from <code>ProductBase&lt;T&gt;</code>.
  For this purpose I want to use something like this:</p>
  <pre><code>public static void DoSomething(ProductBase&lt;ModifierBase&lt;ItemBase&gt;&gt; item)
  {
      Console.WriteLine(item.Name);
  }
  </code></pre>
  <p>The issue here is that I cannot pass parameters to it:</p>
  <pre><code>Product product1 = new Product();
  DoSomething(product1);
  
  ProductFromOtherSystem product2 = new ProductFromOtherSystem();
  DoSomething(product2 as ProductBase&lt;ModifierBase&lt;ItemBase&gt;&gt;);
  </code></pre>
  <p>The error is like</p>
  <blockquote>
  <p>Cannot convert type _ to _ via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion</p>
  </blockquote>
  <p>I've tried to downcast it somehow but have not found any solution. I wonder if it is possible to do it?</p>