title: Call GetStoredProcCommand with variable number of arguments in C#?
body: <p>In my code I am repeating code blocks like this all the time:</p>
  
  <pre><code>var returnData = MyDb.ExecuteDataSet(
      MyDb.GetStoredProcCommand("MyTable_Insert", columnOne, columnTwo, columnThree),
      transaction
  );
  
  var returnId = (int)returnData.Tables[0].Rows[0]["INSERTED_ID"];
  </code></pre>
  
  <p>This seems to me to be a fairly large block of code to be repeating so many times, but I can't work out how to generalise it into a method because the number of arguments is different to each stored procedure.</p>
  
  <p>The obvious solution (to me) is to pass my parameters through to the function in an array and then expand them to call <code>GetStoredProcCommand</code>, but I can't find a way to do this:</p>
  
  <pre><code>private int CallStoredProcedure(string procName, List&lt;dynamic&gt; parameterValues) {
      ..
      MyDb.GetStoredProcCommand(procName, expand parameterValues);
      // ERROR: Obviously "expand" doesn't exist
      ..
  }
  </code></pre>
  
  <p>I could use the longer-winded way passing parameters using <code>AddInParameter</code>, but then I would need to pass type information along with the parameter values:</p>
  
  <pre><code>private int CallStoredProcedure(string procName, IDictionary&lt;DbType, IDictionary&lt;string, string&gt;&gt; paramsKeyValuesByType) {
      ..
      MyDb.AddInParameter(myProcCommand, param.Value.Key, param.Key, param.Value.Value);
      ..
  }
  </code></pre>
  
  <p>But then I'd have to construct the <code>IDictionary</code> object before calling the method which would be even more long-winded than how I was originally calling the procedure.</p>
  
  <p>Can anyone think of an elegant solution to this?</p>