目前,我在我的配置文件中得到了类似下面这样的东西:
<blah.mail>
<templates>
<add name="TemplateNbr1" subject="..." body="Hi!\r\nThis is a test.\r\n.">
<from address="blah@hotmail.com" />
</add>
</templates>
</blah.mail>我希望能够将body表示为template的子节点(即上面示例中的add节点),以如下所示结束:
<blah.mail>
<templates>
<add name="TemplateNbr1" subject="...">
<from address="blah@hotmail.com" />
<body><![CDATA[Hi!
This is a test.
]]></body>
</add>
</templates>
</blah.mail>发布于 2009-01-21 12:35:29
在您的自定义配置元素类中,您需要覆盖方法OnDeserializeUnrecognizedElement。
示例:
public class PluginConfigurationElement : ConfigurationElement
{
public NameValueCollection CustomProperies { get; set; }
public PluginConfigurationElement()
{
this.CustomProperties = new NameValueCollection();
}
protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader)
{
this.CustomProperties.Add(elementName, reader.ReadString());
return true;
}
}我不得不解决同样的问题。
发布于 2009-01-17 20:02:57
在ConfigurationElement子类中,尝试使用XmlWriter.WriteCData重写SerializeElement以写入数据,并使用XmlReader.ReadContentAsString重写DeserializeElement以读回数据。
https://stackoverflow.com/questions/422230
复制相似问题