mirror of https://github.com/oliverbooth/X10D
Add generic DiscordEmbedBuilder.AddField<T>
This commit is contained in:
parent
0163c82197
commit
178cfca1d8
|
@ -7,6 +7,34 @@ namespace X10D.DSharpPlus;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DiscordEmbedBuilderExtensions
|
public static class DiscordEmbedBuilderExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a field of any value type to the embed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The <see cref="DiscordEmbedBuilder" /> to modify.</param>
|
||||||
|
/// <param name="name">The name of the embed field.</param>
|
||||||
|
/// <param name="value">The value of the embed field.</param>
|
||||||
|
/// <param name="inline"><see langword="true" /> to display this field inline; otherwise, <see langword="false" />.</param>
|
||||||
|
/// <typeparam name="T">The type of <paramref name="value" />.</typeparam>
|
||||||
|
/// <returns>The current instance of <see cref="DiscordEmbedBuilder" />; that is, <paramref name="builder" />.</returns>
|
||||||
|
/// <exception cref="ArgumentNullException"><paramref name="builder" /> is <see langword="null" />.</exception>
|
||||||
|
public static DiscordEmbedBuilder AddField<T>(
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Conditionally adds a field to the embed.
|
/// Conditionally adds a field to the embed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue