Esempio n. 1
0
        public ReplCommandBuilder WithPositional(string name, Action <ReplCommandPositionalParameterBuilder>?config = null)
        {
            var parameterBuilder = new ReplCommandPositionalParameterBuilder().WithName(name);

            config?.Invoke(parameterBuilder);
            this.parameters.Add(parameterBuilder);
            return(this);
        }
Esempio n. 2
0
        private static void BuildPositionalParameter(
            ReplBuilder builder,
            ReplCommandBuilder commandBuilder,
            ParameterInfo parameter,
            ReplParamAttribute replParam,
            ReplCommandPositionalParameterBuilder paramBuilder)
        {
            if (replParam.TypeName == null)
            {
                throw new ArgumentNullException(nameof(replParam.TypeName));
            }

            paramBuilder
            .WithTypeName(replParam.TypeName)
            .WithCaption(replParam.Caption)
            .WithDescription(replParam.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);
                    });
                }
            }
        }