aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-11-20 16:24:28 -0600
committerGitHub <noreply@github.com>2021-11-20 16:24:28 -0600
commit951f447d7b7412ea54f16dda9641b884594740ff (patch)
tree1bb6c425a782b4e748e51cfecd1a6cdca367c1b8 /src/slskd/Common
parent56339e50cc78e963b9634143af0986919cad4d43 (diff)
parentc9934c3a232d42d4199f1f284ed00a614803059c (diff)
downloadslskd-951f447d7b7412ea54f16dda9641b884594740ff.tar.gz
Merge branch 'master' into bump
Diffstat (limited to 'src/slskd/Common')
-rw-r--r--src/slskd/Common/Extensions.cs13
-rw-r--r--src/slskd/Common/ManagedState.cs2
2 files changed, 13 insertions, 2 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()
{
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));