title: How to optimize redundant code in c#?
body: <p>I have the following class. EDITED: (And I know it's not a good practice):</p>
  
  <pre><code>public class BussinesRuleA
  {
      private string _connectionString;
  
      public BussinesRuleA(string connectionString)
      {
          _connectionString = connectionString;
      }
  
      public List&lt;persitenceRuleA&gt; getDATA_A(persitenceRuleA perRA, int acao)
      {
          //EDITED: IT´S MANDATORY make A NEW instance to this DATA ACCESS class
          //        The connectionString was removed from the constructor 
          dalRuleA dalRA = new dalRuleA(); 
          List&lt;persitenceRuleA&gt; lst = new List&lt;persitenceRuleA&gt;();
          try
          {
              lst = dalRA.getDATA(perRA, acao);
          }
          catch (Exception e)
          {
              throw e;
          }
          finally
          {
              dalRA = null;
          }
          return lst;
      }
  }
  </code></pre>
  
  <p>I Want to do the same thing in Generic way. How can I recreate the code to the method above?
  I try to do the code below but it´s not working. <strong>EDITED:</strong> The name of the method was changed</p>
  
  <pre><code>    public List&lt;TPer&gt; getDATA_Generic&lt;TPer, TDal&gt;(TPer per, int acao) 
             where TDal: new()
      {
          TDal _dal = new TDal(); 
          List&lt;TPer&gt; _lst = new List&lt;TPer&gt;();
          try
          {
              _lst = _dal.getDATA(TPer,acao); //**EDITED**: The call for getDATA method was changed 
          }
          catch (Exception e)
          {
              throw e;
          }
          finally
          {
              _dal = default(TDal);
          }
          return _lst;
      }
  </code></pre>
  
  <p><strong>EDITED</strong>: The code above works, but I dont want to do:</p>
  
  <pre><code>    public List&lt;TPer&gt; getDATA&lt;TPer, TDal&gt;(TPer per, int acao) 
  </code></pre>
  
  <p><strong>EDITED</strong>: Instead, I want something like this :</p>
  
  <pre><code>    public List&lt;TPer&gt; getDATA&lt;TPer&gt;(TPer per, int acao) 
  </code></pre>
  
  <p><strong>EDITED</strong>: And create a new instance of TDal inside the method, i dont know if it's possible, or if exists a workaround to solve this issue:</p>
  
  <pre><code>    TDal _dal = new TDal(); 
  </code></pre>
  
  <p>Actually I have several class, something like that:    </p>
  
  <pre><code>    BussinesRuleA: method getDATA, call to persitenceRuleA , dalRuleA
      BussinesRuleB: method getDATA, call to persitenceRuleB , dalRuleB
      BussinesRuleC: method getDATA, call to persitenceRuleC , dalRuleC
  </code></pre>
  
  <p>I want to reduce the rewrite of code,  avoiding have to write a lot of methods, I want to use TPer and TDal with generics to make this:</p>
  
  <pre><code>    BussinesRuleA: method getDATA&lt;T&gt;, call to TPer , TDal
      BussinesRuleB: method getDATA&lt;T&gt;, call to TPer , TDal
      BussinesRuleC: method getDATA&lt;T&gt;, call to TPer , TDal
  </code></pre>