123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #region
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- #endregion
- namespace CassiniDev.UIComponents
- {
- public sealed class CommandLine
- {
- #region Fields
- private readonly string[] _arguments;
- private readonly bool _showHelp;
- private IDictionary _options;
- #endregion
- #region Constructors
- public CommandLine(string[] args)
- {
- ArrayList list = new ArrayList();
- for (int i = 0; i < args.Length; i++)
- {
- char ch = args[i][0];
- if ((ch != '/') && (ch != '-'))
- {
- list.Add(args[i]);
- }
- else
- {
- int index = args[i].IndexOf(':');
- if (index == -1)
- {
- string strA = args[i].Substring(1);
- if ((string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0) || strA.Equals("?"))
- {
- _showHelp = true;
- }
- else
- {
- Options[strA] = string.Empty;
- }
- }
- else
- {
- Options[args[i].Substring(1, index - 1)] = args[i].Substring(index + 1);
- }
- }
- }
- _arguments = (string[]) list.ToArray(typeof (string));
- }
- #endregion
- #region Properties
- public string[] Arguments
- {
- get { return _arguments; }
- }
- public IDictionary Options
- {
- get
- {
- if (_options == null)
- {
- _options = new HybridDictionary(true);
- }
- return _options;
- }
- }
- public bool ShowHelp
- {
- get { return _showHelp; }
- }
- #endregion
- }
- }
|