コード例 #1
0
        public CommandOptionDescriptor(Type optionType, string name, IReadOnlyList <char> shortName, string description, CoconaDefaultValue defaultValue, string?valueName, CommandOptionFlags flags, IReadOnlyList <Attribute> parameterAttributes)
        {
            OptionType          = optionType ?? throw new ArgumentNullException(nameof(optionType));
            Name                = name ?? throw new ArgumentNullException(nameof(name));
            ShortName           = shortName ?? throw new ArgumentNullException(nameof(shortName));
            Description         = description ?? throw new ArgumentNullException(nameof(description));
            DefaultValue        = defaultValue;
            ValueName           = valueName ?? OptionType.Name;
            Flags               = flags;
            ParameterAttributes = parameterAttributes;

            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("A name of the command option must not be empty.", nameof(name));
            }
            if (defaultValue.HasValue && defaultValue.Value != null && defaultValue.Value.GetType() != optionType)
            {
                throw new ArgumentException($"The type of default value is not compatible with type of option.: OptionType={optionType.FullName}; ValueType={defaultValue.Value.GetType().FullName}");
            }
        }
コード例 #2
0
        private CommandOptionDescriptor CreateCommandOption(Type optionType, string name, IReadOnlyList <char> shortName, string description, CoconaDefaultValue defaultValue, CommandOptionFlags flags = CommandOptionFlags.None)
        {
            var optionValueName = (DynamicListHelper.IsArrayOrEnumerableLike(optionType) ? DynamicListHelper.GetElementType(optionType) : optionType).Name;

            return(new CommandOptionDescriptor(optionType, name, shortName, description, defaultValue, optionValueName, flags, Array.Empty <Attribute>()));
        }
コード例 #3
0
 public CommandOptionLikeCommandDescriptor(string name, IReadOnlyList <char> shortName, CommandDescriptor command, CommandOptionFlags commandOptionFlags)
 {
     Name      = name ?? throw new ArgumentNullException(nameof(name));
     ShortName = shortName ?? throw new ArgumentNullException(nameof(shortName));
     Command   = command ?? throw new ArgumentNullException(nameof(command));
     Flags     = CommandOptionFlags.OptionLikeCommand | commandOptionFlags;
 }