I have a console application taking as input dozens of parameters. I'm using commandlineparser to help myself and i have no problem setting values to properties.
By the way I also have a lot of methods i need to recall.
The methods i need to call take as input any number of parameters between 0 and 7; some method is parameterless, most method take at least 3 parameters as input.
Searching for a solution for the easiest case (parameterless method) i came up with this solution: I introduced a new boolean property called IsExecuteOperation, i set this property, let commandlineparser do its job and then check the value and eventually call the method like this:
class Program
{
static void Main( string[] args )
{
Parser.Default.ParseArguments<Options>( args )
.WithParsed<Options>( o =>
{
if( o.IsExecuteOperation )
{
o.ExecuteOperation();
}
} );
}
public class Options
{
public bool IsExecuteOperation { get; set; }
public void ExecuteOperation()
{
//...
}
}
}
This looked like a good idea so i went this way with all the other parameterless methods.
The parameterless methods are 7 so, i have 7 options more to deal with, plus the additional code to check this flags and call the methods.
I proceeded to deal with the methods taking as input 1 param (2 methods).
The first method takes as input a number: this results in 2 new properties (1 for the method parameter + 1 property needed to signal wether to execute the method) + the additional code to check and execute the method itself.
The problem arises with the second single-param method: it takes as input an object that internally defines at least 9 properties that i absolutely need to be set to execute the method correctly.
Well i could have introduced those 9 properties too but at this point i just realized that it would have been technically possible but impractical and messy to apply the same approach for all my methods (50ish) and introduce hundreads of properties just to call those methods.
My question.. is my approach correct? Is there any better strategy to solve this? Is there a way to call methods directly?
Thank you.