I currently have a .NET custom configurationsection that looks like this:
<customSection name="My section" />
What I want is to write it as a textnode (I'm not sure if this is the correct term?) like this:
<customSection>
<name>My Section</name>
</customSection>
My current customSection class looks like this:
public class CustomSection: ConfigurationSection {
[ConfigurationProperty("name")]
public String Name {
get {
return (String)this["name"];
}
}
}
What should I do to make it a textnode?
A bit of research suggests that the existing configuration classes do not support that type of element without creating a custom class to handle it. This CodeProject article covers creating a new
ConfigurationTextElement
class that is generic and can parse a serialized string into an object (including a string, which is what the article shows).The class code is brief:
If you want to be able to have both attributes as well as text content e.g.
Then you can override
DeserializeElement
like so:Hope this helps.