title: Referencing various Action<...> variable types with a single type?
body: <p>In my application I have the need to reference various types of <code>Action</code></p>
  
  <pre><code>Action action1;
  Action&lt;int&gt; action2; 
  
  Action actRef = action2; // Error: actRef is not the same type as action2
  </code></pre>
  
  <p>Basically I would like a type with which I can reference both <code>action1</code> and <code>action2</code>. Is this possible?</p>
  
  <hr>
  
  <p>The best solution I can think of is to wrap the <code>Action&lt;...&gt;</code> in another class that implements some interface.</p>
  
  <pre><code>public interface MyInterfaceType
  {
  
  }
  
  public class MyActionWrapper : MyInterfaceType
  {
      public Action MyAction { get; set; }
  }
  
  public class MyActionWrapper&lt;T&gt; : MyInterfaceType 
  {
      public Action&lt;T&gt; MyAction { get; set; }
  }
  </code></pre>
  
  <p>Then carry around references to <code>MyInterfaceType</code>.</p>
  
  <pre><code>public class MyActionsHolder
  {
      List&lt;MyInterfaceType&gt; MyActions { get; set; }
  
      public void DoActions()
      {
          foreach(MyInterfaceType anAction in MyActions)
          {
              if(anAction is MyActionWrapper)
                  ((MyActionWrapper)anAction).MyAction();
              else if(anAction is MyActionWrapper&lt;int&gt;)
                  ((MyActionWrapper&lt;int&gt;)anAction).MyAction(1);
          }
      }
  }
  </code></pre>
  
  <p>Is there a better solution? Or a way to clean this solution up?</p>
  
  <hr>
  
  <p>More background on the specifics. I have written a simple scripting language which I am trying to parse into <code>Action</code>, each <code>Action</code> represents a parsed command from the script. As one commentor pointed out I can easily just wrap an <code>Action</code> with another</p>
  
  <pre><code>Action myParameterlessAction = new Action(() =&gt; MySingleParmAction(1));
  </code></pre>
  
  <p>though for a few of my commands I allow the user to supply a psuedo argument/variable. For example I might have an argument <code>FOO</code> that allows one argument. The argument is either a value for <code>FOO</code> or it is a "variable" meaning the current value of <code>FOO</code> when the command is executed.</p>
  
  <pre><code>FOO 231     // Set FOO = 231
  FOO VAL_FOO // Set FOO to the desired value of FOO, whatever it may be at this time
  </code></pre>
  
  <p>So when I go to parse this second type of command I create an <code>Action</code> that takes a parameter so I can supply it when the time comes. </p>
  
  <pre><code>Action fooCommand1 = new Action(delegate() { MyForm.SetFooValue(231); });
  Action&lt;int&gt; fooCommand2 = MyForm.SetFooValue;
  </code></pre>
  
  <p>I would like to be able to collect all <code>Action</code> create from parsing into a <code>List&lt;...&gt;</code> that I can then loop over and execute each action.. (I do realize that I will need a method to determine which <code>Action</code> need parameters supplied and how to determine what to supply them with; based on my solution above this information would be in <code>MyInterfaceType</code> most likely).</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> In response to @The Anathema's answer, I have a command in my language that allows a user to wait for some period of time before continuing. The parsing of the script to the <code>Action</code> would look like this</p>
  
  <pre><code>public KeyValuePair&lt;Delegate, object[]&gt; CommandAction { get; set; }
  ...
  Action commandDelegate = new Action(async delegate()
  {
      await Task.Delay(msWait);
  });
  result.CommandAction = new KeyValuePair&lt;Delegate, object[]&gt;(commandDelegate, null);
  </code></pre>
  
  <p>Will <code>Action.DynamicInvoke</code> block until the <code>Task.Delay(...)</code> has completed? Where will the invocation happen, on the current thread or the thread on which the <code>Action</code> was created? Can I change either of these options?</p>
  
  <p>Also per this <a href="https://stackoverflow.com/a/12858434/2985796">SO answer</a> I take it it would be worthwhile to try to resolve the <code>Action</code>s that are parameterless to <code>Action myAct</code> so that I can <code>Invoke</code> them instead of <code>DynamicInvoke</code> (Seeing that <code>DynamicInvoke</code> takes orders of magnitude longer to execute per the linked answer)?</p>