From 178cfca1d85bdfddaf3bc3b40be9bfb0b8f99dbd Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 21 Jul 2022 11:43:05 +0100 Subject: [PATCH] Add generic DiscordEmbedBuilder.AddField --- .../src/DiscordEmbedBuilderExtensions.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs b/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs index fb21b85..e93c42b 100644 --- a/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs @@ -7,6 +7,34 @@ namespace X10D.DSharpPlus; /// public static class DiscordEmbedBuilderExtensions { + /// + /// Adds a field of any value type to the embed. + /// + /// The to modify. + /// The name of the embed field. + /// The value of the embed field. + /// to display this field inline; otherwise, . + /// The type of . + /// The current instance of ; that is, . + /// is . + public static DiscordEmbedBuilder AddField( + this DiscordEmbedBuilder builder, + string name, + T? value, + bool inline = false) + { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(builder); +#else + if (builder is null) + { + throw new ArgumentNullException(nameof(builder)); + } +#endif + + return builder.AddField(name, value?.ToString(), inline); + } + /// /// Conditionally adds a field to the embed. ///