I am working on a project in which I need to define any number of possible parameters when creating an object.
public class base
{
//Variable Declarations here...
public base(){ //Handle Arguments here... }
}
public class customCommand : base
{
//Action Logic here...
}
My main issue comes from the declarations of "customCommand" (sorry for the poor naming conventions.) If the user wants to create an object that passes no further parameters, then the declaration works perfectly. However, If the user wants to create an object that does pass a parameter, I need to handle this with a new declaration. The purpose of the script is to allow the user to create a command for a command-prompt-esc simulator. I have an 'interpreter' that will pass any parameters into the method that is associated with the command. My interpreter already "handles" type safety by returning whatever error the assigned function returns in a formatted way to the user. If the user needs to type "command1 [string] [int]" but they type "command1 [string] [string]", for example, the interpreter will see that the function assigned returned a type-error along with the type needed, and tell the user to try the command again with the correct syntax.
I would define command1 by creating an object like this:
private static customCommand<string,int> command1;
and I would define the method the command uses (for the interpreter) like this:
command1 = new customCommand<string,int>((x,y) =>
{
//some method
});
public class customCommand<T1> : base
{
//New Action Logic here (handles T1)...
}
I understand one solution to this is simply limiting the user's ability to create an object with 'n' number of parameters, and writing out new definitions of new with <T1> * n
parameters each, like:
public class customCommand<T1> : base { }
public class customCommand<T1,T2> : base { }
public class customCommand<T1,T2,T3> : base { } etc...
however, the possible inputs the user would have could exceed 10-11 entries, which would not only be a pain to manage in 10-11 different declarations but would also serve a messy solution.
I tried creating a class with an empty list of parameters. I expected to be able to create an object in which I could pass any number of parameters I needed.
public class customCommand<new T[]> { };
private static customCommand<string, string, int> test; //parameters are just an example
Any help would be appreciated, I am still learning. Thank you! (sorry for poor formatting, im trying to edit the post for the comments while running be
I need to define any number of possible parameters
why? What's the actual problem that would solve? Why use even 3 types instead of just 1 with 3 properties? If the class is supposed to do something, why not useAction<>
orFunc<>
?