feature: Add a way to invoke a command specifying optional values by name (#1123)

* Add NamedArgumentTypeAttribute

* Add NamedArgumentTypeReader

* Fix superflous empty line.

* Fix logic for quoted arguments

* Throw an exception with a tailored message.

* Add a catch to wrap parsing/input errors

* Trim potential excess whitespace

* Fix an off-by-one

* Support to read an IEnumerable property

* Add a doc

* Add assertion for the collection test
This commit is contained in:
Joe4evr
2018-11-07 00:36:44 +01:00
committed by Christopher F
parent 8ef5f8120f
commit 419c0a5b53
7 changed files with 369 additions and 9 deletions

View File

@@ -0,0 +1,11 @@
using System;
namespace Discord.Commands
{
/// <summary>
/// Instructs the command system to treat command paramters of this type
/// as a collection of named arguments matching to its properties.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class NamedArgumentTypeAttribute : Attribute { }
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Reflection;
namespace Discord.Commands
@@ -27,8 +26,8 @@ namespace Discord.Commands
/// => ReplyAsync(time);
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class OverrideTypeReaderAttribute : Attribute
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class OverrideTypeReaderAttribute : Attribute
{
private static readonly TypeInfo TypeReaderTypeInfo = typeof(TypeReader).GetTypeInfo();