msnCommand.cs

 
 1  using System;
 2  using System.Diagnostics;
 3
 4  namespace MS.StrongName.ManagedSN
 5  {
 6       /// <summary>
 7       ///      Handler for a specific command line option
 8       /// </summary>
 9       /// <param name="arguments">List of all the command line options</param>
10      public delegate int OptionHandler(string[] arguments);
11
12       /// <summary>
13       ///      Utility class linking an option switch, its implementation, and help about it
14       /// </summary>
15      internal sealed class Command : IComparable
16      {
17          private string              option;
18          private OptionHandler       handler;
19          private string              arguments;
20          private string              help;
21
22           /// <summary>
23           ///      Initialize a SN command
24           /// </summary>
25           /// <param name="option">switch that enters this command</param>
26           /// <param name="handler">implementation of the command</param>
27           /// <param name="arguments">Names of the arguments this command takes</param>
28           /// <param name="help">help string for the command</param>
29          internal Command(string option, OptionHandler handler, string arguments, string help)
30          {
31              Debug.Assert(!String.IsNullOrEmpty(option), "Empty option switch");
32              Debug.Assert(handler != null);
33              Debug.Assert(!String.IsNullOrEmpty(help), "Empty command help");
34
35              this.option = option;
36              this.handler = handler;
37              this.arguments = arguments;
38              this.help = help;
39
40              return;
41          }
42
43           /// <summary>
44           ///      Switch that enters this command
45           /// </summary>
46          public string Option { get { return option; } }
47
48           /// <summary>
49           ///      Implementation of the command
50           /// </summary>
51          public OptionHandler Handler { get { return handler; } }
52
53           /// <summary>
54           ///      Names of the arguments this command needs
55           /// </summary>
56          public string Arguments
57          {
58              get
59              {
60                  if(arguments == null)
61                      return String.Empty;
62                  else
63                      return arguments;
64              }
65          }
66
67           /// <summary>
68           ///      Help string for the command
69           /// </summary>
70          public string Help { get { return help; } }
71
72           /// <summary>
73           ///      Comparison function to sort by option
74           /// </summary>
75          public int CompareTo(object obj)
76          {
77              Command other = obj as Command;
78
79              Debug.Assert(other != null);
80              if(other == null)
81                  throw new InvalidOperationException(Resources.CompareToNonCommand);
82
83              return Option.CompareTo(other.Option);
84          }
85      }
86  }