diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-11-11 18:31:54 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-11-11 18:31:54 -0600 |
| commit | 90ba9a27a1997bdf53f5f73a891c1a642796ab7e (patch) | |
| tree | baa06a0a290de162172fcef804c2b28e3d1870a1 /src | |
| parent | bf274ffeb48ec3ae5dc872299db4b34201a8a604 (diff) | |
| download | slskd-90ba9a27a1997bdf53f5f73a891c1a642796ab7e.tar.gz | |
add FromYaml, rename ToObject to FromJson
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 13 | ||||
| -rw-r--r-- | src/slskd/Common/ManagedState.cs | 2 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 03bec7fe..678b790c 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() { diff --git a/src/slskd/Common/ManagedState.cs b/src/slskd/Common/ManagedState.cs index 26fbcb2a..bf6565db 100644 --- a/src/slskd/Common/ManagedState.cs +++ b/src/slskd/Common/ManagedState.cs @@ -184,7 +184,7 @@ namespace slskd { lock (Lock) { - var previous = CurrentValue.ToJson().ToObject<T>(); + var previous = CurrentValue.ToJson().FromJson<T>(); CurrentValue = setter(CurrentValue); Changed?.Invoke((previous, CurrentValue)); |
