From a8523c5ebdb5ff5f214001dc9a0bb09885f6577c Mon Sep 17 00:00:00 2001
From: Suiram1701 <110390261+Suiram1701@users.noreply.github.com>
Date: Sat, 26 Apr 2025 21:40:21 +0200
Subject: [PATCH] Fixed modals with value type properties (#3091)
* Fixed type reader/converter parsing exception
* Fixed modals with value types properties
* Made OverridesToString result lazy and store it
---
.../IDiscordInteractionExtensions.cs | 7 ++++-
.../InputComponents/TextInputComponentInfo.cs | 10 +++++++
.../Utilities/ReflectionUtils.cs | 30 +++++++++++++++++--
3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs b/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs
index 377d6730..37522633 100644
--- a/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs
+++ b/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs
@@ -68,8 +68,13 @@ namespace Discord.Interactions
{
case TextInputComponentInfo textComponent:
{
+ var boxedValue = textComponent.Getter(modal);
+ var value = textComponent.TypeOverridesToString
+ ? boxedValue.ToString()
+ : boxedValue as string;
+
builder.AddTextInput(textComponent.Label, textComponent.CustomId, textComponent.Style, textComponent.Placeholder, textComponent.IsRequired ? textComponent.MinLength : null,
- textComponent.MaxLength, textComponent.IsRequired, textComponent.Getter(modal) as string);
+ textComponent.MaxLength, textComponent.IsRequired, value);
}
break;
default:
diff --git a/src/Discord.Net.Interactions/Info/InputComponents/TextInputComponentInfo.cs b/src/Discord.Net.Interactions/Info/InputComponents/TextInputComponentInfo.cs
index 613549fe..6831c795 100644
--- a/src/Discord.Net.Interactions/Info/InputComponents/TextInputComponentInfo.cs
+++ b/src/Discord.Net.Interactions/Info/InputComponents/TextInputComponentInfo.cs
@@ -1,3 +1,5 @@
+using System;
+
namespace Discord.Interactions
{
///
@@ -5,6 +7,12 @@ namespace Discord.Interactions
///
public class TextInputComponentInfo : InputComponentInfo
{
+ ///
+ /// true when overrides .
+ ///
+ internal bool TypeOverridesToString => _typeOverridesToString.Value;
+ private readonly Lazy _typeOverridesToString;
+
///
/// Gets the style of the text input.
///
@@ -37,6 +45,8 @@ namespace Discord.Interactions
MinLength = builder.MinLength;
MaxLength = builder.MaxLength;
InitialValue = builder.InitialValue;
+
+ _typeOverridesToString = new(() => ReflectionUtils