Antmicro.OptionsParser.CommandLineOptionDescriptor.CommandLineOptionDescriptor C# (CSharp) Method

CommandLineOptionDescriptor() public method

public CommandLineOptionDescriptor ( PropertyInfo pinfo ) : System
pinfo System.Reflection.PropertyInfo
return System
        public CommandLineOptionDescriptor(PropertyInfo pinfo)
            : this()
        {
            var nameAttribute = pinfo.GetCustomAttribute<NameAttribute>();
            if(nameAttribute != null)
            {
                ShortName = nameAttribute.ShortName;
                LongName = nameAttribute.LongName;
            }
            else
            {
                ShortName = char.ToLower(pinfo.Name.ElementAt(0));
                LongName = ShortName + pinfo.Name.Substring(1);
            }

            OptionType = pinfo.PropertyType;

            UnderlyingProperty = pinfo;

            IsRequired = (pinfo.GetCustomAttribute<RequiredAttribute>() != null);
            AcceptsArgument = (pinfo.PropertyType != typeof(bool));
            AllowMultipleOccurences = pinfo.PropertyType.IsArray;

            var defaultValueAttribute = pinfo.GetCustomAttribute<DefaultValueAttribute>();
            if(defaultValueAttribute != null)
            {
                if(OptionType != defaultValueAttribute.DefaultValue.GetType())
                {
                    throw new ArgumentException(string.Format("Default value for option '{0}' is of unexpected type.", LongName ?? ShortName.ToString()));
                }
                DefaultValue = defaultValueAttribute.DefaultValue;
            }

            var descriptionAttribute = pinfo.GetCustomAttribute<DescriptionAttribute>();
            if(descriptionAttribute != null)
            {
                Description = descriptionAttribute.Value;
            }

            if(OptionType.IsArray)
            {
                var numberOfElementsAttribute = pinfo.GetCustomAttribute<NumberOfElementsAttribute>();
                if(numberOfElementsAttribute != null)
                {
                    MaxElements = numberOfElementsAttribute.Max;
                }
                var delimiterAttribute = pinfo.GetCustomAttribute<DelimiterAttribute>();
                if(delimiterAttribute != null)
                {
                    Delimiter = delimiterAttribute.Delimiter;
                }
            }
        }

Same methods

CommandLineOptionDescriptor::CommandLineOptionDescriptor ( ) : System
CommandLineOptionDescriptor::CommandLineOptionDescriptor ( char shortName, Type type ) : System
CommandLineOptionDescriptor::CommandLineOptionDescriptor ( char shortName, string longName, Type type ) : System
CommandLineOptionDescriptor::CommandLineOptionDescriptor ( string longName, Type type ) : System
CommandLineOptionDescriptor