title: Casting DataRow to Strongly-Typed DataRow: How do they do it?
body: <p>I'm trying to make a lightweight version of some strongly-typed DataRows in order to write a test for a method that takes <code>IEnumerable&lt;T&gt; where T : DataRow</code>.</p>
  
  <p>I would like to make a class that inherits from <code>DataRow</code> but has additional properties, as in the autogenerated strongly-typed DataSet.Designer.cs. I cannot get their code to work, and indeed I don't understand how it <em>could</em> work:</p>
  
  <pre class="lang-cs prettyprint-override"><code>// from AnimalDataSet.Designer.cs:
  [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  public AnimalRow AddAnimalRow(
          string Name, 
          int Species_ID) {
      AnimalRow rowAnimalRow = ((AnimalRow)(this.NewRow()));
      object[] columnValuesArray = new object[] {
          null,
          Name,
          Species_ID};
      rowAnimalRow.ItemArray = columnValuesArray;
      this.Rows.Add(rowAnimalRow);
      return rowAnimalRow;
  }
  </code></pre>
  
  <p>Every time I try to run an imitation of this - I get InvalidCastException (Unable to cast object of type System.DataRow to type AnimalRow). As I would have expected.</p>
  
  <p>So what makes their code more special?</p>