title: How to Properly use Custom Class Generics
body: <p>I am trying to use Custom Generic class and interface.Im having problems to find a solution for the logic and code of my small Project.</p>
  
  <p>THE BLUEPRINT INTERFACE</p>
  
  <pre><code> public interface IDepartment&lt;T&gt;
      {
          T CreateAndGetValues(SqlDataReader dataReader);   
  
      }
  </code></pre>
  
  <p>THE POSSIBLE DTO</p>
  
  <pre><code> public class Bank&lt;T&gt; : IDepartment&lt;T&gt;
      {
          public int LfdNr { get; set; }
  
          public string Kennung { get; set; }
  
          public string Name { get; set; }
  
          public string Straße { get; set; }
  
          public string PLZ { get; set; }
  
          public string Ort { get; set; }
  
          public DateTime TSCREATE { get; set; }
  
          public DateTime TSUPDATE { get; set; }
  
          public T CreateAndGetValues(SqlDataReader dataReader)
          {
  
              Bank&lt;T&gt; TheReturnObject = new Bank&lt;T&gt;();
              ThereturnObject.LfdNr = Convert.ToInt32(dataReader.GetValue(0));
              ThereturnObject.Kennung = dataReader.GetValue(1).ToString();
              ThereturnObject.Name = dataReader.GetValue(2).ToString();
              ThereturnObject.Straße = dataReader.GetValue(3).ToString();
              ThereturnObject.PLZ = dataReader.GetValue(4).ToString();
              ThereturnObject.Ort = dataReader.GetValue(5).ToString();
              ThereturnObject.TSCREATE = DateTime.ParseExact(dataReader.GetValue(6).ToString().Trim(), "dd.MM.yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
              ThereturnObject.TSUPDATE = DateTime.ParseExact(dataReader.GetValue(7).ToString().Trim(), "dd.MM.yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
              return TheReturnObject;
          }                
      }
  </code></pre>
  
  <p>THE GENERAL DATABASE READER.</p>
  
  <pre><code>public class Mssql&lt;T&gt; where T :class, IDepartment&lt;T&gt;, new()
      {
          public List&lt;T&gt; ReadTable()
          {
              string sqlcommand = "Select * from Bank; ";
              List&lt;T&gt; TheListofObject = new List&lt;T&gt;();
              using (SqlConnection cnn = new SqlConnection(connetionString))
              {
                  cnn.Open();
                  using (SqlCommand command = new SqlCommand(sqlcommand, cnn))
                  {
                      SqlDataReader dataReader;
                      try
                      {
                          dataReader = command.ExecuteReader();
  
                          while (dataReader.Read())
                          {
                              IDepartment&lt;T&gt; Object = new T();
                              Object.CreateAndGetValues(dataReader);                            
                              TheListofObject.Add(Object);
                          }                        
                          return TheListofObject;
                      }                    
                      catch (Exception ex)
                      {
                          throw;
                      }
                      dataReader.Close();
                  }
                  cnn.Close();
              }
  
          }
      }
  </code></pre>
  
  <p>THE MAIN PROGRAM</p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              Mssql&lt;Bank&lt;T&gt;&gt; TEST = new Mssql&lt;Bank&lt;T&gt;&gt;();
              List&lt;Bank&lt;T&gt;&gt; TheList = TEST.ReadTable();
  
              Console.ReadLine();
  
          }
      }
  </code></pre>
  
  <p>I am expecting that i can use a interface with a method where classes can inherit and return a new type of itself with the Type T and to pass the Type. So that the classes are not dependent that much to each other. And code can be reusable. I hope that is not confusing. Thanks</p>