我有一堆我想訂閱的通用事件,並使它們都調用一個非泛型方法。這裏是我的代碼:.Net生成通用方法
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)
{
}
顯然這不起作用,有沒有辦法做一個包裝的泛型方法?
啓發? – nawfal