Exemplo n.º 1
0
        private static void BuildOptionParameter(
            ReplBuilder builder,
            ReplCommandBuilder commandBuilder,
            ParameterInfo parameter,
            ReplOptionAttribute replOption,
            ReplCommandOptionParameterBuilder paramBuilder)
        {
            if (replOption.TypeName == null)
            {
                throw new ArgumentNullException(nameof(replOption.TypeName));
            }

            paramBuilder
            .WithTypeName(replOption.TypeName)
            .WithCaption(replOption.Caption)
            .WithValueCount(replOption.ValueCount)
            .WithDescription(replOption.Caption);

            if (!parameter.HasDefaultValue)
            {
                paramBuilder.WithIsRequired();
            }

            if (parameter.ParameterType.IsGenericType &&
                parameter.ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable <string>).GetGenericTypeDefinition())
            {
                paramBuilder.WithIsRepeated();
            }

            foreach (var replExample in parameter.GetCustomAttributes <ReplExampleAttribute>())
            {
                paramBuilder.WithExample(replExample.Command, exampleBuilder =>
                {
                    exampleBuilder
                    .WithCaption(exampleBuilder.caption)
                    .WithDescription(exampleBuilder.description);
                });

                if (replExample.Scope >= ReplExampleScope.Parent)
                {
                    commandBuilder.WithExample(replExample.Command, exampleBuilder =>
                    {
                        exampleBuilder
                        .WithCaption(exampleBuilder.caption)
                        .WithDescription(exampleBuilder.description);
                    });
                }

                if (replExample.Scope >= ReplExampleScope.All)
                {
                    builder.WithExample(replExample.Command, exampleBuilder =>
                    {
                        exampleBuilder
                        .WithCaption(exampleBuilder.caption)
                        .WithDescription(exampleBuilder.description);
                    });
                }
            }
        }
Exemplo n.º 2
0
        public ReplCommandBuilder WithOption(string name, Action <ReplCommandOptionParameterBuilder>?config = null)
        {
            var parameterBuilder = new ReplCommandOptionParameterBuilder().WithName(name);

            config?.Invoke(parameterBuilder);
            this.parameters.Add(parameterBuilder);
            return(this);
        }