I have a class, let's call it class1. class1 contains an event, event1. Consider this code snippet:
class1 cls = new class1();
class1 copy = cls.Clone();
The Clone method does what its name suggests, it clones the object cls. I want the callback method associated the event event1 in cls to be associated with the event event1 in copy. In other words, I want to clone (transfer) the association so that when event1 fires in copy, the same callback method is associated with cls is invoked.
How can I do that?
copy.event = this.event;
If you own the class, you can assign the event to the new event in the clone method.
If you don't own the class, use reflection.
Open in new window