diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-11-08 18:55:36 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-11-08 18:55:36 -0600 |
| commit | d0ef56835155e0c93393eee660297cddfb3f9cca (patch) | |
| tree | f54a0cef747335e04beefdab253a5f8a834f6195 /src | |
| parent | 5db9f135d959b97e72ade83988db62b24467d04a (diff) | |
| download | slskd-d0ef56835155e0c93393eee660297cddfb3f9cca.tar.gz | |
add ToYaml()
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 12 |
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 |
