Command Line Switch Parser


I didn’t write it
(Peter Hallam did), but I was just using it and thought “wow, this is cool, it
needs to be found by more people!”


If you build console apps that take
multiple arguments (generate.exe /vroot:vbasic /target:c:\files\ … etc.) then
href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=62a0f27e-274e-4228-ba7f-bc0118ecc41e"> face="Trebuchet MS" color=teal>this color=teal> makes it very easy. To use it, just compile the provided code into a
library and reference from your own C#, VB.NET, etc. application.


From the readme;



href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=62a0f27e-274e-4228-ba7f-bc0118ecc41e">Command
Line Argument Parser
—————————-


Author: href="mailto:peterhal@microsoft.com"> face="Courier New">peterhal@microsoft.com


Parsing command line arguments to a console
application is a common problem.
This library handles the common task of
reading arguments from a command line
and filling in the values in a
type.


To use this library, define a class whose fields
represent the data that your
application wants to receive from arguments
on the command line. Then call

Utilities.Utility.ParseCommandLineArguments() to fill the object with the
data
from the command line. Each field in the class defines a command line
argument.
The type of the field is used to validate the data read from the
command line.
The name of the field defines the name of the command line
option.


The parser can handle fields of the following
types:


– string
– int
– uint
– bool

enum
– array of the above type


 


Comments (10)

  1. Anonymous says:

    Command Line Parsing with XmlSerializer : NUnitAddin

  2. Hi Duncan,

    I’ve commented about another way of doing this on my blog.

    http://dotnetweblogs.com/nunitaddin

  3. I’m pleased you liked it. 😉 BTW have you had a chance to try NUnitAddin? I used it extensively when knocking together that code. It’s one of those applications that’s easy to dogfood…

    See ya, Jamie.

  4. Joel.... says:

    Love that line…"wow, this is cool, it needs to be found by more people"…. and to solve that, you stuck it on your blog…you must get a lot of traffic. Actually, I know a lot of people who regular this place of fine tea.

  5. Joel, the trick is not that I get a lot of traffic… but that content on my blog is much more likely to be found by a google search than in many other places.

  6. http://www.sellsbrothers.com's Genghis project has an alternate approach I use when writing console app’s.

  7. Voltan says:

    This library ("Command Line Argument Parser", by Peter Hallam) is very great. I think it can be improved. I emailed the author but did not get any answer. I’d like to improve this and publish a new version, but I need Peter’s agreement.

  8. SweetChildOMine says:

    Guns and Roses is one of the best bands ever.

  9. Rod says:

    I disagree. Shampoo is better.

  10. Bill says:

    Conditioner is better.

Skip to main content