is there kinda getOptions available?

  • Thread starter Thread starter Dave Sexton
  • Start date Start date
D

Dave Sexton

Hi,

I don't think it exists in the FCL.

It's not really that difficult without one though. You can take a string[] in
the main method as such:

static void Main(string[] args)
{
}

From here it's a simple matter of iterating the string collection and figuring
out if each value corresponds to a switch that is supported in your
application. The supported formats of the switches are entirely up to you.
 
Hello Twig,

Specify the "string[] args" as the Main method signature and use args to
manipulate with your command line args.
Another case is to use Environment.CommandLine property


T> Really, can't find built-in lib for commandline argument handling.
T> Maybe I'm just missing it? Is it so?!
T>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
Twig said:
Really, can't find built-in lib for commandline argument handling.
Maybe I'm just missing it? Is it so?!

I don't think there is one. You simply use the "Main" overload that takes
an array of strings, to get at the individual command line arguments. Any
further processing of those arguments, you'll have to handle yourself.
 
Really, can't find built-in lib for commandline argument handling.
Maybe I'm just missing it? Is it so?!
 
As other have indicated there's nothing out of the box.
Chris Sells had quite a nice attributes based approach using attributes in
his (and others') Attila project.
I am sure I have also seen this approach in an MSDN magazine article
(although Google is failing me now search for "command line parser
attributes" or similar)
 
then reflection and attributes are your friends. see my post below.

Twig said:
Dave Sexton kirjoitti:
Hi,

I don't think it exists in the FCL.

It's not really that difficult without one though. You can take a
string[] in the main method as such:

static void Main(string[] args)
{
}

From here it's a simple matter of iterating the string collection and
figuring out if each value corresponds to a switch that is supported in
your application. The supported formats of the switches are entirely up
to you.

Yeah, I know. It is just so common thing to do that I thought it is better
to ask whether there's one.
I am just heavy coder but lazy typist./
 
Twig said:
Dave Sexton kirjoitti:
Hi,

I don't think it exists in the FCL.

It's not really that difficult without one though. You can take a string[] in
the main method as such:

static void Main(string[] args)
{
}

From here it's a simple matter of iterating the string collection and figuring
out if each value corresponds to a switch that is supported in your
application. The supported formats of the switches are entirely up to you.

Yeah, I know. It is just so common thing to do that I thought it is
better to ask whether there's one.
I am just heavy coder but lazy typist./

I found several once on GotDotNet user samples:

http://www.gotdotnet.com/community/usersamples/

If you can't find it, I have one I could post.
 
Dave Sexton kirjoitti:
Hi,

I don't think it exists in the FCL.

It's not really that difficult without one though. You can take a string[] in
the main method as such:

static void Main(string[] args)
{
}

From here it's a simple matter of iterating the string collection and figuring
out if each value corresponds to a switch that is supported in your
application. The supported formats of the switches are entirely up to you.

Yeah, I know. It is just so common thing to do that I thought it is
better to ask whether there's one.
I am just heavy coder but lazy typist./
 
Twig said:
Really, can't find built-in lib for commandline argument handling.
Maybe I'm just missing it? Is it so?!

In addition to using a string[] in main as the others suggested, you
can also use System.Environment.CommandLine to get a string with the
command line arguments in it.
 
Bruce Wood kirjoitti:
Twig said:
Dave Sexton kirjoitti:
Hi,

I don't think it exists in the FCL.

It's not really that difficult without one though. You can take a string[] in
the main method as such:

static void Main(string[] args)
{
}

From here it's a simple matter of iterating the string collection and figuring
out if each value corresponds to a switch that is supported in your
application. The supported formats of the switches are entirely up to you.
Yeah, I know. It is just so common thing to do that I thought it is
better to ask whether there's one.
I am just heavy coder but lazy typist./

I found several once on GotDotNet user samples:

http://www.gotdotnet.com/community/usersamples/

If you can't find it, I have one I could post.

Got It. Kiitos.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top