Skip to content

Instantly share code, notes, and snippets.

@pilotgeraldb
Created June 21, 2016 14:21
Show Gist options
  • Save pilotgeraldb/32c8e933cfa3dc57b3e2211a1944a3bb to your computer and use it in GitHub Desktop.
Save pilotgeraldb/32c8e933cfa3dc57b3e2211a1944a3bb to your computer and use it in GitHub Desktop.
deserializes a section in the config file
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