Reading a Recipe to control data processing steps
<p>I have a text file in the general format:</p>

<pre><code>ThreadID, MethodName, [Param1 | Param2 | ... ]
</code></pre>

<p>And I have a Utility class that looks like:</p>

<pre class="lang-cs prettyprint-override"><code>public static class Util
{
    public static List&lt;double&gt; Foo(List&lt;double&gt; Source, double Scale)
    {
        List&lt;double&gt; l = new List&lt;double&gt;(Source);
        for (int i = 0; i &lt; l.Count; i++)
        {
            l[i] = l[i] * Scale;
        }
        return l;
    }

    public static void Fud(List&lt;double&gt; Source, string Name)
    {
        //... Chart Series
    }
    public static bool Fee(CustomClass MyClass, double Limit1, int Limit2)
    {
        //... Test MyClass values against input limits
        return true; // false;
    }
}
</code></pre>

<p>So I was using a switch/case which given the method name from the text file, would then parse and pass along arguments to the method in the case.  The sudo code was something to the effect of:</p>

<pre class="lang-cs prettyprint-override"><code>    static void Main(string[] args)
    {
        List&lt;string&gt; TextFile;
        List&lt;double&gt;[] Register = new List&lt;double&gt;[3];   //lists containing data that is moved, mutated and converted to CustomClass
        CustomClass MyClass = new CustomClass();
        bool Passed = false;

        foreach (var line in TextFile)
        {
            string methodName = Util.ParseMethod(line);          //parsed from file
            string param1, param2, param3, param4 = Util.ParseParams(line);          //parsed from file
            switch (methodName)
            {
                case "Foo":
                    Register[param1] = Util.Foo(Register[param2], param3);
                    break;

                case "Fud":
                    Util.Fud(Register[param1], param3);
                    break;

                case "Fee":
                    Passed = Util.Foo(MyClass, param1, param2);
                    break;
            }
        }
    }
</code></pre>

<p>I disliked having the logic split up and every time I develop a new utility method, I have to manually add another case statement.  The case statement became difficult to maintain because design time errors (typos in strings/updates) usually only got caught during run-time.</p>

<p>I tried to convert this all to a Factory architecture, but I can't seem to accommodate for the different method definitions.  I was hoping to do away with the Utility class and define each method in it's own class using a factory interface.</p>

<pre class="lang-cs prettyprint-override"><code>public interface IRecipe
{
    string GetFactoryKey();
    string SerializeArgs(object[] args);
    object[] DeserializeArgs(string args);
    ??? DoWork(???);
}
</code></pre>

<p>The problem is because of how different each method in the utility class was, I can't find a way to define it in the Interface properly.  The end result I want is that I can replace the switch in the foreach loop with generic code and that all the nitty gritty logic, parsing, method definitions, error checking and validation is defined in each class implementing the factory interface and not the method caller.  I've run out of things to google for as I don't know what I want to do is even called.</p>
