I'm working on a personal project to build a Truth Table Generator, with an emphasis on collecting/cementing what I'm learning about logical equivalence.
As such, I'm trying to write it in such a way that it takes a C# Function as an argument. I'll turn it into a "build a compiler project" later, but for now I want to learn more about delegates, metaprogramming, and have fun with logical equivalence while at it.
So, what I'm trying to figure out is how syntactically I would define a Delegate that takes 1 to N boolean arguments, such that I avoid violating DRY like this...
public delegate bool OneArgFunc(bool arg1);
public delegate bool TwoArgFunc(bool arg1, bool arg2);
public delegate bool ThreeArgFunc(bool arg1, bool arg2, bool arg3);
public delegate bool OuchieThisIsStartingToHurt(bool arg, bool arg, bool arg...);
...and I don't believe the below will do it, as "ListOnlyFunc" takes a list of type boolean as a single argument--when what I want is a delegate that can accept a boolean function with two boolean arguments, or a function with 1200 boolean arguments.
public delegate bool ListOnlyFunc(bool[] args); // Nope!
Part of the reason I want to avoid that latter is that I want to be able to extract the argument names from the function, as well (instead of displaying generic indexed arguments). For instance, if I run the below I should see "foo, baz, turkey" in the output window; I don't want to simply get the count of the number of arguments and output an index ("1, 2, 3").
public CSharpBoolDelegate MyFunc(bool foo, bool baz, bool turkey)
{
//does things
}
public class Program
{
static void Main(string[] args)
{
IStatementSniffer sniffer = new CSharpFunctionSniffer(myFunc);
sniffer.printArgs();
}
}
If you have any tips on how I could approach this (or if it is even possible), advice would be greatly appreciated. :)
Thanks,
Chris