title: C# - specific type method declaration inside a generic class
body: <p>I'm trying to achieve a general purpose "mutable" method using a generic class, i don't know if C# can achieve this. I'll explan the situation: I have a class that represents an entity in a database whose properties are marked with attributes [PrimaryKey] and [Field]. Example:</p>
  
  <pre><code>    public class Car :TableEntity
      {
           [Field]
           [PrimaryKey]
           public string RegNumber{get;set;}
           [Field]
           public string Color{get;set;}
      }
  </code></pre>
  
  <p>What I try to achieve is that instantiating a generic class using a TableEntity class, the .GetOne() method automatically change its parameters to be those of the primary keys, but I have not been able to find an elegant way to do it.</p>
  
  <p>For example, i have:</p>
  
  <pre><code>public class BusinessObject&lt;T&gt; where T:TableEntity
  {
  public T GetOne(); //this is the method to modify depending on which type is T
  }
  </code></pre>
  
  <p>and if i do </p>
  
  <pre><code>BusinessObject&lt;Car&gt; BO = new BusinessObject&lt;Car&gt;();
  </code></pre>
  
  <p>i should see in the Intellisense:</p>
  
  <pre><code>BO.GetOne(string RegNumber);
  </code></pre>
  
  <p>Is there a way or a workaround to achieve this? I know that using System.Reflection i can extract the parameter names and types which are marked as [PrimaryKey], but i don't know if i can modify a method declaration "on the air". </p>
  
  <p>Thank you very much!</p>