I have many functions that are currently overloaded to work on int and string :
bool foo(int); bool foo(string); bool bar(int); bool bar(string); void baz(int p); void baz(string p);
Then I have many functions that take 1, 2, 3, or 4 arguments, either int , or string , that call the above functions:
void g(int p1) { if(foo(p1)) baz(p1); } void g(string p1) { if(foo(p1)) baz(p1); } void g(int p2, int p2) { if(foo(p1)) baz(p1); if(bar(p2)) baz(p2); } void g(int p2, string p2) { if(foo(p1)) baz(p1); if(bar(p2)) baz(p2); } void g(string p2, int p2) { if(foo(p1)) baz(p1); if(bar(p2)) baz(p2); } void g(string p2, string p2) { if(foo(p1)) baz(p1); if(bar(p2)) baz(p2); }
Note The implementation of the g() family is just an example
More types can be entered at any time than the current int or string . The same goes for functions with more arguments than 4. The current number of identical functions is little controllable. Add one more option in any dimension, and the combinatorial explosion will be so huge that it can blow away the application.
In C ++, I would plan for g() and execute.
I understand that the varieties of .NET are different. I struggled with them for two hours, trying to come up with a solution that does not require copying and pasting the code, but to no avail.
C # generators will not require me to enter identical code for a family of functions with five arguments of any of the three types?
What am I missing?
Edit: These functions are used to parse a bunch of arguments (currently either int or string ) from some source. Imagine that bar() and baz() can read both int and string , and the g() family defines the type and number of arguments to parse (implicitly, by type of argument).