It depends on whether your events are delegated to the methods defined in the GameObject class, or whether they are passed to another instance of the observer class.
If events are processed in methods defined in your GameObject class, and you want events in the clone to be processed using methods in your clone instance, you can get a usage reflection to get information about the method from the original event handlers, create a new delegate using the cloned instance and method name, and then designate the new delegate as the cloned event handler.
public GameObject Clone() { var clone = new GameObject(); foreach (var target in this.Initialize.GetInvocationList()) { var mi = target.Method; var del = Delegate.CreateDelegate( typeof(EventHandler<EventArgs>), clone, mi.Name); clone.Initialize += (EventHandler<EventArgs>)del; } return clone; }
If the events are processed in another class, you do not need to do anything, but all event notifications for both the source instance and the cloned instance will have the same handlers. If this is not what you want, you will need to change the event delegates after cloning.
source share