This project has moved. For the latest updates, please go here.

What is the purpose for "Has Custom child Elements"

Dec 31, 2007 at 10:58 PM
Hi, I'm trying to understand how to use the "Has Custom child elements flag. Can you elaborate?
Coordinator
Jan 1, 2008 at 1:06 PM
Edited Jan 1, 2008 at 1:07 PM


spascoe64 wrote:
Hi, I'm trying to understand how to use the "Has Custom child elements flag. Can you elaborate?


Basically, the idea is that you have a configuration element that has an XML node inside it which can vary and isn't known at design time. I'll make sure to document this properly, but in the meantime: suppose you have a logging section and a logger that is instantiated through reflection. That logger instance then parses the inner XML to define its settings.

<logger type="Logging.FileLogger, CustomLoggingAssembly">
  <fileOptions filename="c:\log.txt" buffered="true" />
</logger>
So the <fileOptions> tag is only something that the FileLogger class would know about. I might as well plug in another logger type without the <fileOptions> but with <databaseOptions> instead. So the child element is custom depending on the logger type.

The "Has Custom Child Elements" flag does two things to help in this regard:
  • It generates an "OnDeserializeUnrecognizedElement" method in the ConfigurationElement class so that a partial class definition can implement the required logic to handle the child XML. You will notice that the generated code does not compile because it calls a "HandleUnrecognizedElement" method that you need to implement (the point where the compilation error occurs contains comments on how to implement that).
  • It indicates in the generated XSD for the Configuration Section that the XML node that has the flag set can have any inner content (otherwise the XML with the inner tag would not be valid according to the XSD).

That was the quick explanation, I'll add this to the main documentation (which is admittedly still a bit sparse).