title: Pass function as a parameter to Action
body: <p>I am trying to pass a method as an action, but it seems that that the casting is not per say. </p>
  
  <p>This is how I am doing it:</p>
  
  <pre><code>public class RequestHandler&lt;T&gt; where T : struct
  {
      public enum EmployeeRequests { BasicDetails, DependentsAndEmergencyContacts , MedicalHistory }
  
      protected Dictionary&lt;T, Action&gt; handlers = new Dictionary&lt;T, Action&gt;();
  
      protected EmployeeManagement empMgmnt = new EmployeeManagement();
  
      public void InitializeHandler(int employeeID)
      {
  
          this.AddHandler(EmployeeRequests.BasicDetails, () =&gt; empMgmnt.GetEmployeeBasicDetails(0));
      }
  
      public void AddHandler(T caseValue, Action action)
      {
          handlers.Add(caseValue, action);
      }
  
      public void RemoveHandler(T caseValue)
      {
          handlers.Remove(caseValue);
      }
  
      public void ExecuteHandler(T actualValue)
      {
          ExecuteHandler(actualValue, Enumerable.Empty&lt;T&gt;());
      }
  
      public void ExecuteHandler(T actualValue, IEnumerable&lt;T&gt; ensureExistence)
      {
          foreach(var val in ensureExistence)
              if (!handlers.ContainsKey(val))
                  throw new InvalidOperationException("The case " + val.ToString() + " is not handled.");
          handlers[actualValue]();
      }
  }
  </code></pre>
  
  <p>And this is my function that I am passing as a parameter:</p>
  
  <pre><code>public object GetEmployeeBasicDetails(int employeeID)
  {
      return new { First_Name = "Mark", Middle_Initial = "W.", Last_Name = "Rooney"};
  }
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <blockquote>
    <p>Overloaded method has some invalid arguments.</p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is how I manage to get around this:</p>
  
  <pre><code>public static class RequestHandler
  {
      public enum EmployeeRequests { BasicDetails = 0, DependentsAndEmergencyContacts = 1 , MedicalHistory = 2 }
  
      private static Dictionary&lt;EmployeeRequests, Func&lt;object&gt;&gt; handlers = new Dictionary&lt;EmployeeRequests, Func&lt;object&gt;&gt;();
  
      public static void InitializeHandler(int employeeID)
      {
          Func&lt;object&gt; EmpBasicDetails = delegate { return EmployeeManagement.GetEmployeeBasicDetails(0); };
          AddHandler(EmployeeRequests.BasicDetails, EmpBasicDetails);
      }
  
      private static void AddHandler(EmployeeRequests caseValue, Func&lt;object&gt; empBasicAction)
      {
          handlers.Add(caseValue, empBasicAction);
      }
  
      public static void RemoveHandler(int caseValue)
      {
          var value = (EmployeeRequests)Enum.Parse(typeof(EmployeeRequests), caseValue.ToString());
          handlers.Remove(value);
      }
  
      public static object ExecuteHandler(int actualValue)
      {          
          var request = (EmployeeRequests)Enum.Parse(typeof(EmployeeRequests), actualValue.ToString());
          return handlers[(EmployeeRequests)request]();
      }
  }
  </code></pre>