Parsing command line arguments with C# is not that easy as with Linux as it doesn’t come with a getopt parsing library. To do that with Windows you need third party libs/classes like NConsoler. I googled for it, grabbed the latest copy, added it to the C# project and it was working out of the box. Here an example how you can use it with your C# app.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using NConsoler;
 
 
 
 
namespace GetOptReplacement
{
    class Program
    {
        /*
         * Main Entrypoint
         */
        static void Main(string[] args)
        {
            Console.Clear();
            Consolery.Run(typeof(Program), args);
        }
 
 
 
        /*
         * 
         */
        [Action]
        public static void Hello([Required(Description = "Username")] string Username)
        {
            Console.WriteLine("I say hello to {0} ",Username);
        }
 
 
        /*
         * 
         */
        [Action]
        public static void StartServer(
                [Required(Description = "Servername")] string Servername,
                [Required(Description = "TCPPort")] string TCPPort,
                [Optional(false, "d")] bool Debug)
        {
            Console.WriteLine("Starting \"{0}\" server on port {1}, debugging {2} ...", 
                               Servername, TCPPort, Debug);
        }
    }
}