Beispiel #1
0
        public void ConvertToNumber()
        {
            if (Raw == null || Raw.Length != HEIGHT || Raw.Any(e => e.Length != TOTAL_LENGTH))
            {
                throw new ArgumentException("Raw data is not 3 line long or each line is not 27 characters long");
            }

            StringBuilder builder = new StringBuilder(ACCOUNT_LENGTH);

            for (int i = 0; i < TOTAL_LENGTH; i = i + WIDTH)
            {
                char c = ConvertToNumber(i);
                builder.Append(c);
            }

            Number = builder.ToString();
        }
        /// <summary>
        /// Parses command line arguments into positional arguments, switches and options.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        /// <param name="markedAsOptions">Optional switches to be treated as options separated with '|', ',' or ' ' character.</param>
        public CommandLineArgumentsEx(IEnumerable <string> args = null, string markedAsOptions = null)
        {
            Raw = args?.ToArray() ?? new string[] { };
            string[] marked = markedAsOptions != null?markedAsOptions.Split('|', ',', ' ') : new string[]
            {
            };
            IsEmpty = !Raw.Any();
            var e          = (Raw as IEnumerable <string>).GetEnumerator();
            var positional = new List <string>();
            var switches   = new List <string>();
            var options    = new Dictionary <string, string>();

            while (e.MoveNext())
            {
                var match = RxElement.Match(e.Current);
                if (match.Success)
                {
                    var key = match.Groups[1].Value;
                    if (marked.Any() && marked.Contains(key, StringComparer.Ordinal))
                    {
                        if (e.MoveNext() && !options.ContainsKey(key))
                        {
                            options.Add(key, e.Current);
                        }
                    }
                    else
                    {
                        switches.Add(key);
                    }
                }
                else
                {
                    positional.Add(e.Current);
                }
            }
            Positional = new CommandLinePositionalArgumentCollection(positional);
            Switches   = new CommandLineSwitchCollection(switches);
            Options    = new CommandLineOptionCollection(options);
        }