From 90ba9a27a1997bdf53f5f73a891c1a642796ab7e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 11 Nov 2021 18:31:54 -0600 Subject: add FromYaml, rename ToObject to FromJson --- src/slskd/Common/Extensions.cs | 13 ++++++++++++- src/slskd/Common/ManagedState.cs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') 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 @@ -225,6 +225,17 @@ namespace slskd .Build() .Serialize(obj); + /// + /// Deserializes this string from yaml to an object of type . + /// + /// The type to which to deserialize the string. + /// The string to deserialize. + /// The new object deserialzied from the string. + public static T FromYaml(this string str) => new DeserializerBuilder() + .WithNamingConvention(UnderscoredNamingConvention.Instance) + .Build() + .Deserialize(str); + /// /// Converts a fully qualified remote filename to a local filename based in the provided /// , swapping directory characters for those specific to the local OS, removing any @@ -277,7 +288,7 @@ namespace slskd /// The type to which to deserialize the string. /// The string to deserialize. /// The new object deserialzied from the string. - public static T ToObject(this string str) => JsonSerializer.Deserialize(str, GetJsonSerializerOptions()); + public static T FromJson(this string str) => JsonSerializer.Deserialize(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(); + var previous = CurrentValue.ToJson().FromJson(); CurrentValue = setter(CurrentValue); Changed?.Invoke((previous, CurrentValue)); -- cgit v1.2.3