Not sure if my vernacular is correct so bear with me on this.
I have a public interface being used in plugins, the classes that implement this interface I want to be clone-able while maintaining their declaring type and all properties therein.
I am aware of ICloneable and that I could simply implement that into my interface but I do not want to pass off the requirement to implement the interface onto the plugin developers and want to control it myself.
Also worth noting that it needs to be lightweight and does not need to be deep. I also do not know anything of the declared type at design time other than it implements my plugin interface, so I would need to cast it into its "unknown" source type.
public interface ImyInterface
{
int commonProp {get;set;}
}
// This class and the properties therein are not known at design time
public myObj : ImyInterface
{
int commonProp {get;set;}
int uncommonProp {get;set;}
}
Then I need to call from my application somthing like:
// This is how I generally "activate my plugins"
ImyInterface obj = (ImyInterface)Activator.CreateInstance(type);
// Then elsewhere I need to clone its current state.
var ClonedObj = obj.clone();
I tried this, but it requires me knowing the type at design time.