Exemple #1
0
 public static OptionSpecification WithLongName(this OptionSpecification specification, string newLongName)
 {
     return(new OptionSpecification(
                specification.ShortName,
                newLongName,
                specification.Required,
                specification.SetName,
                specification.Min,
                specification.Max,
                specification.DefaultValue,
                specification.ConversionType,
                specification.HelpText,
                specification.MetaValue));
 }
Exemple #2
0
        public static Specification FromProperty(PropertyInfo property)
        {
            var attrs = property.GetCustomAttributes(true);
            var oa    = attrs.OfType <OptionAttribute>();

            if (oa.Count() == 1)
            {
                var spec = OptionSpecification.FromAttribute(oa.Single(), property.PropertyType);
                if (spec.ShortName.Length == 0 && spec.LongName.Length == 0)
                {
                    return(spec.WithLongName(property.Name.ToLowerInvariant()));
                }
                return(spec);
            }

            var va = attrs.OfType <ValueAttribute>();

            if (va.Count() == 1)
            {
                return(ValueSpecification.FromAttribute(va.Single(), property.PropertyType));
            }

            throw new InvalidOperationException();
        }