The Command Line Argument Handling Library is a library, so it requires to be referenced within your project for it to work.

If you do not know how to reference a library into your project, check out the following page:
https://msdn.microsoft.com/en-us/library/7314433t(v=vs.90).aspx

After referencing it, you can start by using the ArgsHandler library:

using ArgsHandler;

To create an object of the ArgumentManager class, you have to pass in the command line arguments as a string[] parameter. e.g:

var argumentManager = new ArgumentManager(args);

There are several properties in the ArgumentManager, such as:
  • ArgumentManager.UsePrefixes
  • ArgumentManager.PrefixCharacter
  • ArgumentManager.IgnorePrefixDuplicates

UsePrefixes
Specifies if the parsing method should look for prefixes or treat every string as an invidual argument with only data.

127.0.0.1 80

e.g:
argumentManager.UsePrefixes = false;
argumentManager.Parse();
Result:
N/A    127.0.0.1
N/A    80


-IP 127.0.0.1 -Port 80

e.g:
argumentManager.UsePrefixes = true;
argumentManager.Parse();
Result:
IP      127.0.0.1
Port   80


PrefixCharacter
Represents the character used to identify prefixes from simple data.

/IP 127.0.0.1 /Port 80

argumentManager.PrefixCharacter = '/';
argumentManager.Parse();
Result:
IP     127.0.0.1
Port   80


IgnorePrefixDuplicates
Specifies if the parser should take in account prefixes that have already appeared before or not.

-animal Tiger -animal Elephant
argumentManager.IgnorePrefixDuplicates = true;
argumentManager.Parse();
Result:
animal Tiger

&
argumentManager.IgnorePrefixDuplicates = false;
argumentManager.Parse();
Result:
animal Tiger
animal Elephant


ParsingFinished event
When the parsing is finished or an error has occured, the ParsingFinished event is raised. It can be easily set up using a lambda expression:

argumentManager.ParsingFinished += (s, e) =>
{
   Console.WriteLine("Result of operation: " + e.Result);
};

Parse method overloads
The parse methods has 3 overloads:
  • public bool Parse(bool UsePrefixes = true)
  • public bool Parse(bool UsePrefixes = true, char PrefixCharacter = '-')
  • public bool Parse(bool UsePrefixes = true, char PrefixCharacter = '-', bool IgnorePrefixDuplicates = true)

Last edited Jan 13 at 4:56 PM by Wopsx, version 3