namespace ConfigElementTest{ public static class Globals { public static MySection Settings; public static void Load() { try { Settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("mySection") as MySection; } catch (Exception ex) { } } } public class MySection : ConfigurationSection { public MySection() { } [ConfigurationProperty("name"), StringValidator(MaxLength = 10, MinLength = 3)] public string Name { get{return (string) base["name"];} set { base["name"] = value; } } }}
<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="mySection" type="ConfigElementTest.MySection, ConfigElementTest" /> </configSections> <mySection name="Some Name" /></configuration>