Browse Source

changed NameAttribute to work for parameter (#765)

tags/2.0.0-beta
Izumemori Christopher F 7 years ago
parent
commit
9c81ab9fe4
2 changed files with 4 additions and 1 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Attributes/NameAttribute.cs
  2. +3
    -0
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs

+ 1
- 1
src/Discord.Net.Commands/Attributes/NameAttribute.cs View File

@@ -3,7 +3,7 @@ using System;
namespace Discord.Commands namespace Discord.Commands
{ {
// Override public name of command/module // Override public name of command/module
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)]
public class NameAttribute : Attribute public class NameAttribute : Attribute
{ {
public string Text { get; } public string Text { get; }


+ 3
- 0
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs View File

@@ -254,6 +254,9 @@ namespace Discord.Commands
case ParameterPreconditionAttribute precon: case ParameterPreconditionAttribute precon:
builder.AddPrecondition(precon); builder.AddPrecondition(precon);
break; break;
case NameAttribute name:
builder.Name = name.Text;
break;
case RemainderAttribute _: case RemainderAttribute _:
if (position != count - 1) if (position != count - 1)
throw new InvalidOperationException($"Remainder parameters must be the last parameter in a command. Parameter: {paramInfo.Name} in {paramInfo.Member.DeclaringType.Name}.{paramInfo.Member.Name}"); throw new InvalidOperationException($"Remainder parameters must be the last parameter in a command. Parameter: {paramInfo.Name} in {paramInfo.Member.DeclaringType.Name}.{paramInfo.Member.Name}");


Loading…
Cancel
Save