我有一堆我想订阅的通用事件,并让它们都调用一个非通用方法。这是我的代码:
public delegate void PropertyChangedDelegate<OwnerType, PropertyType>(OwnerType sender, PropertyType oldValue, PropertyType newValue);
public class EventObject
{
public event PropertyChangedDelegate<Object, Boolean> PropertyChanged;
public event PropertyChangedDelegate<Object, Int32> XChanged;
}
static void Main()
{
EventObject eventObject = new EventObject();
EventInfo eventInfo = eventObject.GetType().GetEvent("PropertyChanged");
eventInfo.AddEventHandler(eventObject, PropertyChanged);
}
static void PropertyChanged(Object obj, Object oldValue, Object newValue)
{
}
显然这不起作用,有没有办法做一个包装泛型方法?