Mirror of space-wizards/YamlDotNet
Find a file
2022-05-10 10:49:42 +01:00
.github Link to the discussion about the status of the project 2022-04-29 17:11:00 +01:00
build Cleanup 2021-01-14 14:44:24 +00:00
BuildUtils.UnityPrerequisites@0db1240a03 Fix the build 2017-09-27 21:40:32 +01:00
tools Build: Fix typo 2021-04-09 15:08:19 +01:00
YamlDotNet Merge pull request #647 from lahma/struct-mark 2021-11-15 10:20:04 +00:00
YamlDotNet.AotTest Merge branch 'master' into a2937-editorconfig 2021-03-31 15:15:42 +01:00
YamlDotNet.Benchmark Add YamlDotNet.Benchmark 2021-11-15 12:47:46 +02:00
YamlDotNet.Samples Fix code style violations 2021-01-28 16:00:02 +00:00
YamlDotNet.Test Merge pull request #626 from willson556/bugfix/extra-newline 2021-08-06 09:46:59 +01:00
.editorconfig Merge branch 'master' into a2937-editorconfig 2021-03-31 15:15:42 +01:00
.gitignore Add YamlDotNet.Benchmark 2021-11-15 12:47:46 +02:00
.gitmodules Fix some error cases 2020-02-16 18:03:52 +02:00
appveyor.yml Update NuGet API key 2022-01-21 23:53:25 +00:00
build.cmd Add new build system 2021-01-14 16:23:49 +00:00
build.sh Add new build system 2021-01-14 16:23:49 +00:00
CONTRIBUTING.md Link to the discussion about the status of the project 2022-04-29 17:11:00 +01:00
docker-build.sh Ensure that tagged values are properly converted to the destination type 2018-06-13 23:51:32 +01:00
GitVersion.yml Setup a release task to make it easier to release a new version 2019-03-15 17:21:32 +00:00
LICENSE-libyaml Initial import. 2008-07-31 22:35:21 +00:00
LICENSE.txt Add license file to nupkg to fix NU5125 warning 2019-07-17 18:14:55 +03:00
README.md Update README.md 2022-05-10 10:49:42 +01:00
yamldotnet.png Update the package icon 2021-01-21 15:45:12 +00:00
YamlDotNet.sln Add YamlDotNet.Benchmark 2021-11-15 12:47:46 +02:00
YamlDotNet.snk Configure the project assembly signing. 2014-11-09 23:10:05 +00:00
yamldotnet.xcf Update the package icon 2021-01-21 15:45:12 +00:00

YamlDotNet

This project is on hold, and issues or pull requests will probably not be reviewed. See this discussion for more details.

Travis Appveyor NuGet
Travis CI Build status NuGet

YamlDotNet is a YAML library for netstandard and other .NET runtimes.

YamlDotNet provides low level parsing and emitting of YAML as well as a high level object model similar to XmlDocument. A serialization library is also included that allows to read and write objects from and to YAML streams.

YamlDotNet's conformance with YAML specifications:

YAML Spec YDN Parser YDN Emitter
v1.1
v1.2

What is YAML?

YAML, which stands for "YAML Ain't Markup Language", is described as "a human friendly data serialization standard for all programming languages". Like XML, it allows to represent about any kind of data in a portable, platform-independent format. Unlike XML, it is "human friendly", which means that it is easy for a human to read or produce a valid YAML document.

The YamlDotNet library

The library has now been successfully used in multiple projects and is considered fairly stable. It is compatible with the following runtimes:

  • netstandard 2.1
  • netstandard 1.3
  • .NET Framework 4.5
  • Unity Subset v3.5

The following runtimes are also supported, with a few features missing:

  • .NET Framework 3.5
  • .NET Framework 2.0

The library is compatible with mono's Ahead-of-Time compilation (AOT), and should work correctly on platforms that depend on it, such as Unity.

Quick start

Here are some quick samples to get you started which can be viewed in this fiddle.

Serialization from an object to a string

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
...

 var person = new Person
{
    Name = "Abe Lincoln",
    Age = 25,
    HeightInInches = 6f + 4f / 12f,
    Addresses = new Dictionary<string, Address>{
        { "home", new  Address() {
                Street = "2720  Sundown Lane",
                City = "Kentucketsville",
                State = "Calousiyorkida",
                Zip = "99978",
            }},
        { "work", new  Address() {
                Street = "1600 Pennsylvania Avenue NW",
                City = "Washington",
                State = "District of Columbia",
                Zip = "20500",
            }},
    }
};

var serializer = new SerializerBuilder()
    .WithNamingConvention(CamelCaseNamingConvention.Instance)
    .Build();
var yaml = serializer.Serialize(person);
System.Console.WriteLine(yaml);
// Output: 
// name: Abe Lincoln
// age: 25
// heightInInches: 6.3333334922790527
// addresses:
//   home:
//     street: 2720  Sundown Lane
//     city: Kentucketsville
//     state: Calousiyorkida
//     zip: 99978
//   work:
//     street: 1600 Pennsylvania Avenue NW
//     city: Washington
//     state: District of Columbia
//     zip: 20500

Deserialization from a string to an object

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
...

var yml = @"
name: George Washington
age: 89
height_in_inches: 5.75
addresses:
  home:
    street: 400 Mockingbird Lane
    city: Louaryland
    state: Hawidaho
    zip: 99970
";

var deserializer = new DeserializerBuilder()
    .WithNamingConvention(UnderscoredNamingConvention.Instance)  // see height_in_inches in sample yml 
    .Build();

//yml contains a string containing your YAML
var p = deserializer.Deserialize<Person>(yml);
var h = p.Addresses["home"];
System.Console.WriteLine($"{p.Name} is {p.Age} years old and lives at {h.Street} in {h.City}, {h.State}.");
// Output:
// George Washington is 89 years old and lives at 400 Mockingbird Lane in Louaryland, Hawidaho.

More information

More information can be found in the project's wiki.

Installing

Just install the YamlDotNet NuGet package:

PM> Install-Package YamlDotNet

If you do not want to use NuGet, you can download binaries here.

YamlDotNet is also available on the Unity Asset Store.

Contributing

Please read CONTRIBUTING.md for guidelines.

Release notes

Release notes for the latest version