예제 #1
0
        private static Tuple <string, string> SplitByDelimiter(string str, CommandLineSettingsBinderOptions options)
        {
            if (str == null)
            {
                return(null);
            }

            string key, value;

            if (!options.Delimiters.Any())
            {
                key   = str.Trim();
                value = null;
            }
            else
            {
                var indices = options.Delimiters.Where(delimiter => delimiter != null)
                              .Select(d => str.IndexOf(d))
                              .Where(d => d != -1).ToList();

                if (indices.Count == 0)
                {
                    key   = str.Trim();
                    value = null;
                }
                else
                {
                    var idx = indices.OrderBy(i => i).First();
                    key   = str.Substring(0, idx);
                    value = str.Substring(idx + 1);
                }
            }

            return(new Tuple <string, string>(key, value));
        }
예제 #2
0
        public CommandLineSettingsBinder(string[] args, CommandLineSettingsBinderOptions options)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            _options = options ?? throw new ArgumentNullException(nameof(options));

            _argumentStore =
                new Dictionary <string, string>(options.IsCaseSensitive
               ? StringComparer.Ordinal
               : StringComparer.OrdinalIgnoreCase);

            Parse(args);
        }