Beispiel #1
0
        public OptionMap(int capacity, CommandLineParserSettings settings)
        {
            _settings = settings;

            IEqualityComparer<string> comparer = _settings.CaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;

            _names = new Dictionary<string, string>(capacity, comparer);
            _map = new Dictionary<string, OptionInfo>(capacity * 2, comparer);

            if (_settings.MutuallyExclusive)
            {
                _mutuallyExclusiveSetMap = new Dictionary<string, MutuallyExclusiveInfo>(capacity, StringComparer.OrdinalIgnoreCase);
            }
        }
Beispiel #2
0
 // special constructor for singleton instance, parameter ignored
 private CommandLineParser(bool singleton)
 {
     Singleton = singleton;
     _settings = new CommandLineParserSettings(false, false, Console.Error);
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLineParser"/> class,
 /// configurable with a <see cref="CommandLineParserSettings"/> object.
 /// </summary>
 /// <param name="settings">The <see cref="CommandLineParserSettings"/> object is used to configure
 /// aspects and behaviors of the parser.</param>
 public CommandLineParser(CommandLineParserSettings settings)
 {
     _settings = settings;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLineParser"/> class.
 /// </summary>
 public CommandLineParser()
 {
     _settings = new CommandLineParserSettings();
 }
Beispiel #5
0
        public static OptionMap CreateMap(object target, CommandLineParserSettings settings)
        {
            var list = ReflectionUtil.RetrievePropertyList<OptionAttribute>(target);
            if (list != null)
            {
                var map = new OptionMap(list.Count, settings);

                foreach (var pair in list.Where(pair => pair != null && pair.Right != null))
                {
                    map[pair.Right.UniqueName] = new OptionInfo(pair.Right, pair.Left);
                }

                map.RawOptions = target;

                return map;
            }

            return null;
        }