From 35b102a7c01b0544599b2a13a54a77b95d5d2dac Mon Sep 17 00:00:00 2001
From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
Date: Fri, 14 Jun 2024 11:22:40 +0300
Subject: [PATCH] [Feature] Generic autocomplete (#2935)
---
.../Attributes/AutocompleteAttribute.cs | 56 ++++++++++---------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs b/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs
index c8a3428db4..71c1c16a4c 100644
--- a/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs
+++ b/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs
@@ -1,36 +1,38 @@
using System;
-namespace Discord.Interactions
+namespace Discord.Interactions;
+
+///
+/// Set the to .
+///
+[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
+public class AutocompleteAttribute : Attribute
{
///
- /// Set the to .
+ /// Type of the .
///
- [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
- public class AutocompleteAttribute : Attribute
- {
- ///
- /// Type of the .
- ///
- public Type AutocompleteHandlerType { get; }
+ public Type AutocompleteHandlerType { get; }
- ///
- /// Set the to and define a to handle
- /// Autocomplete interactions targeting the parameter this is applied to.
- ///
- ///
- /// must be set to to use this constructor.
- ///
- public AutocompleteAttribute(Type autocompleteHandlerType)
- {
- if (!typeof(IAutocompleteHandler).IsAssignableFrom(autocompleteHandlerType))
- throw new InvalidOperationException($"{autocompleteHandlerType.FullName} isn't a valid {nameof(IAutocompleteHandler)} type");
-
- AutocompleteHandlerType = autocompleteHandlerType;
- }
+ ///
+ /// Set the to and define a to handle
+ /// Autocomplete interactions targeting the parameter this is applied to.
+ ///
+ ///
+ /// must be set to to use this constructor.
+ ///
+ public AutocompleteAttribute(Type autocompleteHandlerType)
+ {
+ if (!typeof(IAutocompleteHandler).IsAssignableFrom(autocompleteHandlerType))
+ throw new InvalidOperationException($"{autocompleteHandlerType.FullName} isn't a valid {nameof(IAutocompleteHandler)} type");
- ///
- /// Set the to without specifying a .
- ///
- public AutocompleteAttribute() { }
+ AutocompleteHandlerType = autocompleteHandlerType;
}
}
+
+///
+/// Set the to .
+///
+/// Type of the that will be used to handle Autocomplete interactions targeting the parameter.
+[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
+public class AutocompleteAttribute() : AutocompleteAttribute(typeof(T))
+ where T : class, IAutocompleteHandler;