aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Extensions.cs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs
index 30b35d14..03bec7fe 100644
--- a/src/slskd/Common/Extensions.cs
+++ b/src/slskd/Common/Extensions.cs
@@ -25,6 +25,8 @@ namespace slskd
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
+ using YamlDotNet.Serialization;
+ using YamlDotNet.Serialization.NamingConventions;
/// <summary>
/// Extensions.
@@ -214,6 +216,16 @@ namespace slskd
public static string ToJson(this object obj) => JsonSerializer.Serialize(obj, GetJsonSerializerOptions());
/// <summary>
+ /// Serializes this object to yaml.
+ /// </summary>
+ /// <param name="obj">The object to serialize.</param>
+ /// <returns>A string containing the serialized object.</returns>
+ public static string ToYaml(this object obj) => new SerializerBuilder()
+ .WithNamingConvention(UnderscoredNamingConvention.Instance)
+ .Build()
+ .Serialize(obj);
+
+ /// <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