Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Accessing grouped settings in a config file but NOT the app.config
- public class CustomFieldElement : ConfigurationElement
- {
- [ConfigurationProperty("fieldName", DefaultValue = "", IsKey = true, IsRequired = true)]
- public string fieldName
- {
- get { return (string)base["fieldName"]; }
- set { base["fieldName"] = value; }
- }
- [ConfigurationProperty("fieldType", DefaultValue = "", IsKey = true, IsRequired = true)]
- public string fieldType
- {
- get { return (string)base["fieldType"]; }
- set { base["fieldType"] = value; }
- }
- [ConfigurationProperty("xpath", DefaultValue = "", IsKey = true, IsRequired = true)]
- public string xpath
- {
- get { return (string)base["xpath"]; }
- set { base["xpath"] = value; }
- }
- }
- [ConfigurationCollection(typeof(CustomFieldElement))]
- public class FieldAppearanceCollection : ConfigurationElementCollection
- {
- internal const string PropertyName = "FieldDescription";
- public override ConfigurationElementCollectionType CollectionType
- {
- get
- {
- return ConfigurationElementCollectionType.BasicMapAlternate;
- }
- }
- protected override string ElementName
- {
- get
- {
- return PropertyName;
- }
- }
- protected override bool IsElementName(string elementName)
- {
- return elementName.Equals(PropertyName, StringComparison.InvariantCultureIgnoreCase);
- }
- public override bool IsReadOnly()
- {
- return false;
- }
- protected override ConfigurationElement CreateNewElement()
- {
- return new CustomFieldElement();
- }
- protected override object GetElementKey(ConfigurationElement element)
- {
- return ((CustomFieldElement)(element)).fieldName;
- }
- public CustomFieldElement this[int idx]
- {
- get
- {
- return (CustomFieldElement)BaseGet(idx);
- }
- }
- }
- public class ConnectionSection : ConfigurationSection
- {
- [ConfigurationProperty("fields")]
- public FieldAppearanceCollection FieldElement
- {
- get { return ((FieldAppearanceCollection)(base["fields"])); }
- set { base["fields"] = value; }
- }
- }
- public class ConfigSettings
- {
- public ConnectionSection CustomFieldAppearanceConfiguration
- {
- get
- {
- return (ConnectionSection)ConfigurationManager.GetSection("customFields");
- }
- }
- public FieldAppearanceCollection CustomFieldApperances
- {
- get
- {
- return this.CustomFieldAppearanceConfiguration.FieldElement;
- }
- }
- public IEnumerable<CustomFieldElement> CustomFieldElements
- {
- get
- {
- foreach (CustomFieldElement selement in this.CustomFieldApperances)
- {
- if (selement != null)
- yield return selement;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment