Exemplo n.º 1
0
        /// <summary>
        /// Find all the constructors for the specified <see cref="Type" /> that have all their parameters
        /// represented as an option.
        /// </summary>
        private IEnumerable <ConstructorInfo> FindSuitableConstructors(Type type)
        {
            return(type.GetConstructors().Where(constructor =>
                                                constructor.GetParameters().All(parameter =>
            {
                if (parameter.ParameterType == typeof(Command))
                {
                    return true;
                }

                var attributes = ArgumentAttribute.For(parameter);

                return attributes.Any()
                        ? attributes.Any(attribute => Options.ContainsKey(attribute.Name))
                        : Options.ContainsKey(parameter.Name);
            })));
        }
Exemplo n.º 2
0
        private void BindProperty(PropertyInfo property, object instance)
        {
            foreach (var attribute in ArgumentAttribute.For(property))
            {
                string text;

                if (!Options.TryGetValue(attribute.Name, out text))
                {
                    continue;
                }

                object value;

                if (BindProvider(property.PropertyType, property.Name, property, out value))
                {
                    property.SetValue(instance, value, null);
                }
            }
        }