public static class EventHandlerExtensions { public static void SafeInvoke<T>(this EventHandler<T> evt, object sender, T e) where T : EventArgs { if (evt != null) { evt(sender, e); } } }
Using that method, you can invoke the events like this: protected void OnSomeEvent(EventArgs e) { SomeEvent.SafeInvoke(this, e); }
时间: 2024-10-08 06:46:55