mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-28 13:44:12 -04:00
parent
e38479d463
commit
7467f0aeb6
2 changed files with 8 additions and 2 deletions
|
@ -37,7 +37,7 @@ public partial record Embed
|
|||
var title = json.GetPropertyOrNull("title")?.GetStringOrNull();
|
||||
|
||||
var kind =
|
||||
json.GetPropertyOrNull("type")?.GetStringOrNull()?.Pipe(s => Enum.Parse<EmbedKind>(s, true)) ??
|
||||
json.GetPropertyOrNull("type")?.GetStringOrNull()?.ParseEnumOrNull<EmbedKind>() ??
|
||||
EmbedKind.Rich;
|
||||
|
||||
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
@ -29,6 +30,11 @@ public static class StringExtensions
|
|||
public static string ToDashCase(this string str) =>
|
||||
Regex.Replace(str, @"(\p{Ll})(\p{Lu})", "$1-$2");
|
||||
|
||||
public static T? ParseEnumOrNull<T>(this string str, bool ignoreCase = true) where T : struct, Enum =>
|
||||
Enum.TryParse<T>(str, ignoreCase, out var result)
|
||||
? result
|
||||
: null;
|
||||
|
||||
public static StringBuilder AppendIfNotEmpty(this StringBuilder builder, char value) =>
|
||||
builder.Length > 0
|
||||
? builder.Append(value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue