Parameter preconditions and typereader overriding
This commit is contained in:
@@ -182,6 +182,10 @@ namespace Discord.Commands
|
||||
// TODO: C#7 type switch
|
||||
if (attribute is SummaryAttribute)
|
||||
builder.Summary = (attribute as SummaryAttribute).Text;
|
||||
else if (attribute is OverrideTypeReaderAttribute)
|
||||
builder.TypeReader = service.GetTypeReader((attribute as OverrideTypeReaderAttribute).TypeReader);
|
||||
else if (attribute is ParameterPreconditionAttribute)
|
||||
builder.AddPrecondition(attribute as ParameterPreconditionAttribute);
|
||||
else if (attribute is ParamArrayAttribute)
|
||||
{
|
||||
builder.IsMultiple = true;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Commands.Builders
|
||||
{
|
||||
public class ParameterBuilder
|
||||
{
|
||||
private readonly List<ParameterPreconditionAttribute> _preconditions;
|
||||
|
||||
public CommandBuilder Command { get; }
|
||||
public string Name { get; internal set; }
|
||||
public Type ParameterType { get; internal set; }
|
||||
@@ -16,16 +20,20 @@ namespace Discord.Commands.Builders
|
||||
public object DefaultValue { get; set; }
|
||||
public string Summary { get; set; }
|
||||
|
||||
public IReadOnlyList<ParameterPreconditionAttribute> Preconditions => _preconditions;
|
||||
|
||||
//Automatic
|
||||
internal ParameterBuilder(CommandBuilder command)
|
||||
{
|
||||
_preconditions = new List<ParameterPreconditionAttribute>();
|
||||
|
||||
Command = command;
|
||||
}
|
||||
//User-defined
|
||||
internal ParameterBuilder(CommandBuilder command, string name, Type type)
|
||||
: this(command)
|
||||
{
|
||||
Preconditions.NotNull(name, nameof(name));
|
||||
Discord.Preconditions.NotNull(name, nameof(name));
|
||||
|
||||
Name = name;
|
||||
SetType(type);
|
||||
@@ -49,7 +57,7 @@ namespace Discord.Commands.Builders
|
||||
}
|
||||
public ParameterBuilder WithDefault(object defaultValue)
|
||||
{
|
||||
DefaultValue = defaultValue;
|
||||
DefaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
public ParameterBuilder WithIsOptional(bool isOptional)
|
||||
@@ -68,6 +76,12 @@ namespace Discord.Commands.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParameterBuilder AddPrecondition(ParameterPreconditionAttribute precondition)
|
||||
{
|
||||
_preconditions.Add(precondition);
|
||||
return this;
|
||||
}
|
||||
|
||||
internal ParameterInfo Build(CommandInfo info)
|
||||
{
|
||||
if (TypeReader == null)
|
||||
|
||||
Reference in New Issue
Block a user