/// <summary> /// Shows how to create .NET objects directly from sections. /// </summary> static void HowToCreateObjectsFromSections() { Configuration cfg = new Configuration(); // Create the section. cfg["SomeStructure"]["SomeString"].SetValue("foobar"); cfg["SomeStructure"]["SomeInt"].SetValue(2000); cfg["SomeStructure"]["SomeDate"].SetValue(DateTime.Now); // Now create an object from it. SomeStructure p = cfg["SomeStructure"].CreateObject <SomeStructure>(); // Test. Console.WriteLine("SomeString: " + p.SomeString); Console.WriteLine("SomeInt: " + p.SomeInt); Console.WriteLine("SomeDate: " + p.SomeDate); }
/// <summary> /// Shows how to create sections directly from C#/.NET objects. /// </summary> static void HowToCreateSectionsFromObjects() { var cfg = new Configuration(); // Create an object. var p = new SomeStructure(); p.SomeString = "foobar"; p.SomeInt = 2000; p.SomeInts = new[] { 1, 2, 3 }; p.SomeDate = DateTime.Now; // Now create a section from it. cfg.Add(Section.FromObject("SomeStructure", p)); // Print the config to see that it worked. PrintConfig(cfg); }