I am trying to work out creating a flexible decorator pattern and visitor pattern. I think I have a decent solution, however in order to make it as flexible as possible I need to have a rather advanced configuration section.
Option 1, create xml serializable object. This could be a night mare due to the complexity and nesting of the xml involved.
Option 2, read the content of the configuration section into an xml document.
Once I have the xml document I can use xpath and such to interpret the contents of the configuration section.
So, I have a class that looks like this:
public class BaseConfigSectionHandler:IConfigurationSectionHandler,IConfigurationSectionHandlerWriter
{
private XmlSerializer _serializer;
public BaseConfigSectionHandler(XmlSerializer serializer)
{
_serializer = serializer;
}
#region IConfigurationSectionHandler Members
public object Create(object parent, object configContext, XmlNode section)
{
object obj = null;
obj = _serializer.Deserialize(new StringReader(section.OuterXml));
return obj;
}
#endregion
}
Then I have another class that Inherits from the class above, and in this derived class, I want to pass an xml serializer to the base class which points to a type of object. The class would look like this:
public class FileMonitorSectionHandler : BaseConfigSectionHandler
{
public FileMonitorSectionHandler():base(new XmlSerializer(typeof(FileMonitorConfig)))
{
}
}
Now, when the create method is called, and instance of FileMonitorConfig would be created and I could interact with the FileMonitorConfig object.
If I wanted to deserialize an xml document instead of FileMonitorConfig, would I simply initialize the base class using base(new XmlSerializer(typeof(XmlDocument))) ?
What happens if you try to use an XmlSerializer to deserialize a string into an XmlDocument?
Thanks in advance