A .NET Yaml Parser.
Map Yaml to .NET objects and vice versa.
// Read a file using a YamlReader
var reader = new YamlReader();
var item = reader.Read<Item>(filepath);
// or
// Read a string using the static Serializer
var item = Serializer.Deserialize<Item>(yml);
// Write a file using a YamlWriter
var writer = new YamlWriter();
writer.Write(filepath, item);
// serialize an object to string
var yml = Serializer.Serialize(item);
- Reading YAML strings to Tokens
- Deserializing YAML string to a POCO
- Writing Tokens to YAML
- Serializing POCO to YAML
Comments
# This is a comment
Properties
Property: Value
Objects
User:
name: John Smith
age: 33
Lists
Movies:
- Casablanca
- Spellbound
- Notorious
Inline Lists
Movies: [Casablanca, Spellbound, Notorious]
Multiline Lists
Movies: [Casablanca,
Spellbound, Notorious]
Quotations
Movies: "Casablanca, Spellbound, Notorious"
Drive: 'c: is a drive'
Blocks
---
Inline Objects
User: {name: John Smith, age: 33}
Block statements
Text: |
There was a young fellow of Warwick
Who had reason for feeling euphoric
For he could, by election
Have triune erection
Ionic, Corinthian, and Doric
WrappedText: >
Wrapped text
will be folded
into a single
paragraph
Blank lines denote
paragraph breaks
To deserialize a Yaml to a object, it is best to have a parameterless constructor.
If a object needs to have a constructor with parameters, the parameter names have to be the same as the properties that they are mapped to.
Else YamlMap will not be able to map the correct values to the parameters.