title: Generic Func<> as parameter to base method
body: <p>I might be losing the plot, but I hope someone can point me in the right direction.</p>
  
  <p>What am I trying to do?</p>
  
  <p>I'm trying to write some base methods which take Func&lt;> and Action so that these methods handle all of the exception handling etc. so its not repeated all over the place but allow the derived classes to specify what actions it wants to execute.</p>
  
  <p>So far this is the base class.</p>
  
  <pre><code>public abstract class ServiceBase&lt;T&gt;
  {
      protected T Settings { get; set; }
  
      protected ServiceBase(T setting)
      {
          Settings = setting;
      }
  
      public void ExecAction(Action action)
      {
          try
          {
              action();
          }
          catch (Exception exception)
          {
              throw new Exception(exception.Message);
          }
      }
  
      public TResult ExecFunc&lt;T1, T2, T3, TResult&gt;(Func&lt;T1, T2, T3, TResult&gt; function)
      {
          try
          {
              /* what goes here?! */
          }
          catch (Exception exception)
          {
              throw new Exception(exception.Message);
          }
      }
  }
  </code></pre>
  
  <p>I want to execute an Action in the following way in the derived class (this seems to work):</p>
  
  <pre><code>public void Delete(string application, string key)
  {
    ExecAction(() =&gt; Settings.Delete(application, key));
  }
  </code></pre>
  
  <p>And I want to execute a Func in a similar way in the derived class but for the life of me I can't seem to workout what to put in the base class.</p>
  
  <p>I want to be able to call it in the following way (if possible):</p>
  
  <pre><code>public object Get(string application, string key, int? expiration)
  {
    return ExecFunc(() =&gt; Settings.Get(application, key, expiration));
  }
  </code></pre>
  
  <p>Am I thinking too crazy or is this possible? Thanks in advance for all the help.</p>