I have the following xml which represents 2 types of plugins, FilePlugin and RegsitryPlugin:
<Client>
<Plugin Type="FilePlugin">
<Message>i am a file plugin</Message>
<Path>c:\</Path>
</Plugin>
<Plugin Type="RegsitryPlugin">
<Message>i am a registry plugin</Message>
<Key>HKLM\Software\Microsoft</Key>
<Name>Version</Name>
<Value>3.5</Value>
</Plugin>
</Client>
I would like to deserialize the xml into objects. As you can see, the 'Message' element is repeating itself both for the FilePlugin and the RegistryPlugin and i am using inheritance for this:
abstract class Plugin
{
private string _message;
protected Plugin(MISSING conf)
{
// here i need to set my private members like:
// Message = MISSING.Message;
}
}
class FilePlugin : Plugin
{
private string _path;
public FilePlugin(MISSING config)
: base(config)
{
// Here i need to set my private members like:
// _path = config.Path;
}
}
class RegistryPlugin : Plugin
{
private string _key;
private string _name;
private string _value;
public RegistryPlugin(MISSING config)
: base(config)
{
// Here i need to set my private members like:
// _key = config.Key;
// _key = config.Name;
// _key = config.Value;
}
}
}
I need somehow to deserialize the xml, and than to decide according the PluginType Element which Instance to create: i.e: if it is written in the xml the Type=FilePlugin than i need to create
Plugin p1 = new FilePlugin(conf);
if it is written in the xml the Type=RegistryPlugin than i need to create
Plugin p2 = new RegistryPlugin(conf);
Please follow my comments in my code in order to understand the missing parts. Thanks