csharpula said:
I have the following situation :
Got a console application (executable) with 6 options such as present
files by date,name,path..
In main i send those arguments to some class and then i need to check
the combinations of them-i can send 1 param,can send any 2,any 3
params....
I need to check which ones exist and to present files which answer to
those criterias. how can i do it without the if(a &b) if(a&b&c)...?
In my opinion, the first thing you need is a command-line argument
parser. I built one myself, but I happen to know that there are at
least three good ones offered for public consumption at gotdotnet
http://www.gotdotnet.com/
A command-line argument parser gives you a framework for offering
flexible command-line arguments to your caller. For example, my parser
allows for positional arguments and named arguments, including mixed
variants, so I can call my program like this:
myprog.exe input.txt /process=summary output.txt /unitofmeasure=lf
and the parser will sort out that I passed two positional arguments
(input.txt and output.txt, 1 and 2, respectively) and supplied the
arguments "process" and "unitofmeasure". It allows me to set default
values for missing arguments, etc, and allows the user to re-order
named arguments without my program having to care.
So, once you're past that point, you now have, in your main program,
some arguments that were supplied and some that were not. I claim that
your main program should then sort out what's what and call one of
several overloads offered by the method or methods that it calls. So,
if the user can pass one, two, or three arguments, and they mean
different things, then you could write three method overloads:
MyMethod(string something, int anotherthing, double yetanotherthing) {
.... }
MyMethod(string something, double yetanotherthing) { ... }
MyMethod(string something) { ... }
and your main program figures out what to pass based on what the user
specified on the command line.
This keeps all of your argument processing in one place: in your main
program, and once you're past that point everything is much tighter.