// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.IO; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; namespace YamlProc.BindCode { public class AB { public int A { get; set; } public int B { get; set; } } public class DE { public string D { get; set; } public string E { get; set; } } public class Config { public AB AB { get; set; } public int C { get; set; } public DE DE { get; set; } public string F { get; set; } } public class Program { public static void Main(string[] args) { IDeserializer dser = (new DeserializerBuilder()).WithNamingConvention(LowerCaseNamingConvention.Instance).Build(); Config cfg = dser.Deserialize(new StreamReader(@"C:\Work\demo1.yaml")); int a = cfg.AB.A; int b = cfg.AB.B; int c = cfg.C; string d = cfg.DE.D; string e = cfg.DE.E; string f = cfg.F; Console.WriteLine("{0} {1} {2} {3} {4} {5}", a, b, c, d, e, f); } } }