|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Handling unknown elements with a ConfigurationElementSince the IConfigurationSectionHandler interface has been deprecated since the introduction of .NET 2.0, I'm trying to use the new configuration classes to handle a custom configuration section. I've gone through all the samples and MSDN docs, but none of them answer my question. What is specific (I think) is that I want to have a child element that is not known until runtime: <processingService> <processes> <process name="Process1" type="SomeNamespace.Process1, SomeAssembly"> ....elements specific to the Process1 class </process> <process name="Process2" type="SomeNamespace.Process2, SomeAssembly"> ....elements specific to the Process2 class </process> </processes> </processingService> Essentially, I want to allow each <process> element to have some child elements only known by the class that it refers to (e.g. Process1). I've defined the ConfigurationSection, ConfigurationElementCollection, ConfigurationElements and ConfigurationProperties as it should, and everything works fine until I add some arbitrary child elements. The configuration framework then throws an exception resulting from the unrecognized elements. As a workaround, I can prevent that exception by overriding the OnDeserializeUnrecognizedElement method of the ConfigurationElement that represents the <process> element. I can even extract the child XML and store it somewhere. But with that, I want to be able to deserialize that XML to a ConfigurationElement subclass provided by the ProcessX class (because they are the only ones who should know what that XML means). Unfortunately, there is no method or interface I can find to manually serialize some XML to a ConfigurationElement subclass. Question 1: What is the preferred way of dealing with unknown child elements in .NET 2.0? Question 2: How can I programmatically (de)serialize XML to/from a ConfigurationElement subclass which has properties that have [ConfigurationProperty] attributes on them. |
|||||||||||||||||||||||