network.piot.yaml-dot-net
v0.0.4
Published
Basic Yaml parser for .NET
Downloads
4
Readme
Yaml dot net
Very lightweight yaml serializer and deserializer.
using Piot.Yaml;
var someObject = new YourClass();
// Convert object to string
var serializedString = YamlSerializer.Serialize(someObject);
// ...and bring it back
var yourObject = YamlDeserializer.Deserialize<YourClass>(serializedString);
Notes
Only supports a small subset of YAML 1.2:
Basic support for float and integers.
Hexadecimal. e.g.
0x3A
.Enums.
FirstEnum
or multiple enum values for flags:FirstChoice | Second
. Optionally it can be formatted asFirstChoice,Second
Alternate serialized name using YamlProperty attribute:
public enum SomeEnum { FirstChoice, Second, [YamlProperty("_third")] Third } public struct SomeStruct { public int answer; [YamlProperty("anotherAnswer")] public string SomethingCompletelyDifferent; }
List / Array
public struct SomeItem { public int x; } public struct RootStruct { public SomeItem[] items; public string somethingElse; }
Can be deserialized from:
items: - x: 42 - x: 98 somethingElse: 'Hello, world!'
Note that it is very picky about the exact indentation.
Dictionary
public struct RootStruct { public Dictionary<int, SomeItem> lookup; public string somethingElse; }
Can be deserialized from example:
lookup: 2: x: 909 -10: x: 1234 somethingElse: 'Hello, world, again'