Ejemplo n.º 1
0
        public void Parse(string[] args)
        {
            var first = args.FirstOrDefault() ?? string.Empty;

            try
            {
                var descriptors = CommandDescriptor.GetMemberDescriptors(this.Instance).ToArray();
                var parser      = new ParseDescriptor(descriptors, args);
                parser.SetValue(this.Instance);
            }
            catch (Exception e)
            {
                if (first == string.Empty)
                {
                    throw new CommandParseException(CommandParseError.Empty, args, true, e);
                }
                if (first == this.HelpName)
                {
                    throw new CommandParseException(CommandParseError.Help, args, true, e);
                }
                if (first == this.VersionName)
                {
                    throw new CommandParseException(CommandParseError.Version, args, true, e);
                }
                throw e;
            }
        }
Ejemplo n.º 2
0
        internal object Invoke(object instance, string[] args, IEnumerable <CommandMemberDescriptor> descriptors)
        {
            var parser            = new ParseDescriptor(descriptors, args);
            var values            = new ArrayList();
            var nameToDescriptors = descriptors.ToDictionary(item => item.DescriptorName);
            var parameters        = this.MethodInfo.GetParameters();

            parser.SetValue(instance);
            foreach (var item in parameters)
            {
                var descriptor = nameToDescriptors[item.Name];
                var value      = descriptor.GetValueInternal(instance);
                values.Add(value);
            }
            return(this.OnInvoke(instance, values.ToArray()));
        }