From d0ef56835155e0c93393eee660297cddfb3f9cca Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 8 Nov 2021 18:55:36 -0600 Subject: add ToYaml() --- src/slskd/Common/Extensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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; /// /// Extensions. @@ -213,6 +215,16 @@ namespace slskd /// A string containing the serialized object. public static string ToJson(this object obj) => JsonSerializer.Serialize(obj, GetJsonSerializerOptions()); + /// + /// Serializes this object to yaml. + /// + /// The object to serialize. + /// A string containing the serialized object. + public static string ToYaml(this object obj) => new SerializerBuilder() + .WithNamingConvention(UnderscoredNamingConvention.Instance) + .Build() + .Serialize(obj); + /// /// 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 -- cgit v1.2.3