using Discord.Net.Converters;
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Discord.Rest
{
///
/// Responsible for formatting certain entities as Json , to reuse later on.
///
public static class StringExtensions
{
private static Lazy _settings = new(() =>
{
var serializer = new JsonSerializerSettings()
{
ContractResolver = new DiscordContractResolver()
};
return serializer;
});
///
/// Gets a Json formatted from an .
///
///
/// See to parse Json back into embed.
///
/// The builder to format as Json .
/// The formatting in which the Json will be returned.
/// A Json containing the data from the .
public static string ToJsonString(this EmbedBuilder builder, Formatting formatting = Formatting.Indented)
=> ToJsonString(builder.Build(), formatting);
///
/// Gets a Json formatted from an .
///
///
/// See to parse Json back into embed.
///
/// The embed to format as Json .
/// The formatting in which the Json will be returned.
/// A Json containing the data from the .
public static string ToJsonString(this Embed embed, Formatting formatting = Formatting.Indented)
=> JsonConvert.SerializeObject(embed.ToModel(), formatting, _settings.Value);
}
}