using System; using System.Configuration; namespace EnVisage.Code.Audit.Configuration { public sealed class AuditConfigurationSection: ConfigurationSection { [ConfigurationProperty("Controllers")] public ControllersCollection Paths => (ControllersCollection)base["Controllers"]; [ConfigurationProperty("enabled", DefaultValue = "false", IsRequired = false)] public Boolean Enabled => (Boolean)this["enabled"]; public static AuditConfigurationSection Current = (AuditConfigurationSection)ConfigurationManager.GetSection("Audit") ?? new AuditConfigurationSection(); public AuditConfigurationSection() { Properties.Add(new ConfigurationProperty("Controllers", typeof(ControllersCollection), new ControllersCollection())); } } [ConfigurationCollection(typeof(ControllerElement))] public class ControllersCollection : ConfigurationElementCollection { protected override ConfigurationElement CreateNewElement() { return new ControllerElement(); } protected override object GetElementKey(ConfigurationElement element) { return ((ControllerElement)element).Path; } public ControllerElement this[int idx] => (ControllerElement)BaseGet(idx); } public class ControllerElement : ConfigurationElement { [ConfigurationProperty("path", DefaultValue = "", IsKey = true, IsRequired = true)] public string Path => (string)base["path"]; } }