diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-11-20 16:36:02 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-11-20 16:36:02 -0600 |
| commit | ef5a4f947727cc41a23a21cb49b228fee5e6af13 (patch) | |
| tree | f9ecc2c08391ed745da08108e0d5f74dc75317c5 /src/slskd/Common/Extensions.cs | |
| parent | d6e62731414ea75fca96265f22997a2d31183b0a (diff) | |
| parent | 9997ee3fc8ac215b3d172b41f76c7e2c227feb40 (diff) | |
| download | slskd-ef5a4f947727cc41a23a21cb49b228fee5e6af13.tar.gz | |
Merge remote-tracking branch 'origin' into bump
Diffstat (limited to 'src/slskd/Common/Extensions.cs')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 79314389..4d463092 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -226,6 +226,17 @@ namespace slskd .Serialize(obj); /// <summary> + /// Deserializes this string from yaml to an object of type <typeparamref name="T"/>. + /// </summary> + /// <typeparam name="T">The type to which to deserialize the string.</typeparam> + /// <param name="str">The string to deserialize.</param> + /// <returns>The new object deserialzied from the string.</returns> + public static T FromYaml<T>(this string str) => new DeserializerBuilder() + .WithNamingConvention(UnderscoredNamingConvention.Instance) + .Build() + .Deserialize<T>(str); + + /// <summary> /// Converts a fully qualified remote filename to a local filename based in the provided /// <paramref name="baseDirectory"/>, swapping directory characters for those specific to the local OS, removing any /// characters that are invalid for the local OS, and making the path relative to the remote store (including the @@ -277,7 +288,7 @@ namespace slskd /// <typeparam name="T">The type to which to deserialize the string.</typeparam> /// <param name="str">The string to deserialize.</param> /// <returns>The new object deserialzied from the string.</returns> - public static T ToObject<T>(this string str) => JsonSerializer.Deserialize<T>(str, GetJsonSerializerOptions()); + public static T FromJson<T>(this string str) => JsonSerializer.Deserialize<T>(str, GetJsonSerializerOptions()); private static JsonSerializerOptions GetJsonSerializerOptions() { |
