Created
June 21, 2016 14:21
-
-
Save pilotgeraldb/32c8e933cfa3dc57b3e2211a1944a3bb to your computer and use it in GitHub Desktop.
deserializes a section in the config file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class XmlDeserializeConfigSectionHandler : IConfigurationSectionHandler | |
{ | |
public XmlDeserializeConfigSectionHandler() : base() | |
{ | |
} | |
public object Create(object parent, object configContext, System.Xml.XmlNode section) | |
{ | |
Type t = this.GetType(); | |
XmlSerializer ser = new XmlSerializer(t); | |
XmlNodeReader xNodeReader = new XmlNodeReader(section); | |
return ser.Deserialize(xNodeReader); | |
} | |
} | |
[Serializable] | |
[XmlRoot("CustomConfig")] | |
public class CustomConfig : XmlDeserializeConfigSectionHandler | |
{ | |
[XmlElement("elementA")] | |
public string elementA { get; set; } | |
[XmlElement("elementB")] | |
public string elementB { get; set; } | |
[XmlElement("elementC")] | |
public string elementC { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment