title: Method overloads which differ only by generic constraint
body: <p>I've run into a bit of a problem, which I simply cannot find a good work-around to.</p>
  
  <p>I want to have these 3 overloads:</p>
  
  <pre><code>public IList&lt;T&gt; GetList&lt;T&gt;(string query) where T: string
  public IList&lt;T&gt; GetList&lt;T&gt;(string query) where T: SomeClass
  public IList&lt;T&gt; GetList&lt;T&gt;(string query) where T: struct
  </code></pre>
  
  <p>Obviously the first constraint won't even compile alone, so that's my first issue. (I realise I could just make it IList but I want the same syntax for the three)</p>
  
  <p>Anyway the reason for all this, is these methods are part of a wrapper around executing SQL queries against a database - I want to be able to return the result as a list of strings (in case someone selects a varchar column), a list of valuetypes (int, float, whatever) or a list of classes (these classes represent tables, and thus contains multiple columns)</p>
  
  <p>I hope that part was somewhat understandable :-)</p>
  
  <p>Anyway my big problem is obviously that I cannot make these overloads, since they use the same name and parameterlist.</p>
  
  <p>Also I cannot merge them into the same method, since I need to call a method on SomeClass in that implementation, so unless I want to do some heavy typecasting, or worse, reflection - I need that constraint.</p>
  
  <p>I realise that what I'm trying to do isn't possible, so what I'm searching for is a good approach, that'll mimic my intentions.</p>
  
  <p>If some of this is a bit unclear, feel free to ask :-)</p>
  
  <p>Edit:</p>
  
  <p>Here's my current code for the "where T: SomeClass" version. I'm trying to add support for string/valuetypes to this current code, so maybe my initial approach is just plain wrong - any ideas are welcome basically :-)</p>
  
  <pre><code>public IList&lt;TValue&gt; GetList&lt;TValue&gt;(string query) where TValue : DbTable, new()
  {
      DataSet dataSet = GetDataSet(query);
      IList&lt;TValue&gt; result = new List&lt;TValue&gt;();
  
      if (dataSet.Tables.Count &gt; 0)
      {
          foreach (DataRow row in dataSet.Tables[0].Rows)
          {
              TValue col = new TValue();
              col.Fill(row);
              result.Add(col);
          }
      }
  
      return result;
  }
  </code></pre>
  
  <p>As you can see I need the exact type of DbTable in order to new the proper constructor.
  Fill is an abstract method of DbTable (which is an abstract class).</p>