예제 #1
0
        public void Parse(OldArgumentSet args)
        {
            Dictionary<PropertyInfo, ArgumentAttribute> props = GetArgumentProperties(GetType());

            //  set property values for anonymous arguments
            AssignAnonymousArguments(args.AnonymousArgs, props);

            //  set property values for each named argument
            AssignNamedArguments(args.NamedArgs, props);

            Validate(props.Keys);
        }
예제 #2
0
        /// <summary>
        /// Parses an array of arguments into
        /// collections of named and anonymous arguments.
        /// </summary>
        public static OldArgumentSet Parse(string[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");

            var set = new OldArgumentSet();

            string name = null;
            for (int i = 0; i < args.Length; i++)
            {
                bool isName = IsName(args[i]);
                bool added = false;
                if (name != null && !isName)
                {
                    set._namedArgs.Add(name, args[i]);
                    added = true;
                }
                else if (name != null)
                {
                    set._namedArgs.Add(name, null);
                    added = true;
                }

                if (added)
                {
                    name = null;
                }

                if (isName)
                {
                    name = GetName(args[i]);
                }
                else if (!added)
                {
                    set._anonymousArgs.Add(args[i]);
                }
            }

            if (name != null)
            {
                set._namedArgs.Add(name, null);
            }

            return set;
        }