Skip to content

Instantly share code, notes, and snippets.

@oscarsan
Created January 21, 2015 12:06
Show Gist options
  • Save oscarsan/2af5c797516d9ee28325 to your computer and use it in GitHub Desktop.
Save oscarsan/2af5c797516d9ee28325 to your computer and use it in GitHub Desktop.
YAMLDOTNET sample
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YamlDotNet.Serialization;
namespace YamlDotNet.Samples
{
public class SerializeObjectGraph
{
public struct Address
{
public string street;
public string city;
public string state;
}
public void Main()
{
var address = new Address
{
street = "123 Tornado Alley\nSuite 16",
city = "East Westville",
state = "KS"
};
var receipt = new
{
receipt = "Oz-Ware Purchase Invoice",
date = new DateTime(2007, 8, 6),
customer = new
{
given = "Dorothy",
family = "Gale"
},
items = new[]
{
new
{
part_no = "A4786",
descrip = "Water Bucket (Filled)",
price = 1.47M,
quantity = 4
},
new
{
part_no = "E1628",
descrip = "High Heeled \"Ruby\" Slippers",
price = 100.27M,
quantity = 1
}
},
bill_to = address,
ship_to = address,
specialDelivery = "Follow the Yellow Brick\n" +
"Road to the Emerald City.\n" +
"Pay no attention to the\n" +
"man behind the curtain."
};
var serializer = new Serializer();
serializer.Serialize(Console.Out, receipt);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment