| @@ -0,0 +1,31 @@ | |||||
| using Discord.Net.Converters; | |||||
| using Newtonsoft.Json; | |||||
| namespace Discord.Rest | |||||
| { | |||||
| /// <summary> | |||||
| /// Responsible for formatting certain entities as json string, to reuse later on. | |||||
| /// </summary> | |||||
| public static class StringExtensions | |||||
| { | |||||
| /// <summary> | |||||
| /// Gets a Json formatted <see langword="string"/> from an <see cref="EmbedBuilder"/> to reuse. | |||||
| /// See <see cref="EmbedBuilder.TryParse(string, out EmbedBuilder)"/> to parse Json back into embeds. | |||||
| /// </summary> | |||||
| /// <param name="builder">The builder to format as Json <see langword="string"/>.</param> | |||||
| /// <param name="formatting">The formatting in which the Json will be returned.</param> | |||||
| /// <returns>A Json <see langword="string"/> containing the data from the <paramref name="builder"/>.</returns> | |||||
| public static string ToJsonString(this EmbedBuilder builder, Formatting formatting = Formatting.Indented) | |||||
| => ToJsonString(builder.Build(), formatting); | |||||
| /// <summary> | |||||
| /// Gets a Json formatted <see langword="string"/> from an <see cref="Embed"/> to reuse. | |||||
| /// See <see cref="EmbedBuilder.TryParse(string, out EmbedBuilder)"/> to parse Json back into embed. | |||||
| /// </summary> | |||||
| /// <param name="embed">The embed to format as Json <see langword="string"/>.</param> | |||||
| /// <param name="formatting">The formatting in which the Json will be returned.</param> | |||||
| /// <returns>A Json <see langword="string"/> containing the data from the <paramref name="builder"/>.</returns> | |||||
| public static string ToJsonString(this Embed embed, Formatting formatting = Formatting.Indented) | |||||
| => JsonConvert.SerializeObject(embed.ToModel(), formatting, new EmbedTypeConverter()); | |||||
| } | |||||
| } | |||||