Snippets code #1 – Extension method to raise an event via reflection

This extension method, applied to the object class and then available for all classes, allows to raise any events via reflection, providing as parameters the event name (as a string) and the TEvenArgs generic parameter.

Example of use:

CustomerViewModel vm = new CustomerViewModel();
vm.Raise("PropertyChanged", new PropertyChangedEventArgs("Name"));

Source for code in this example

Leave a Reply

Your email address will not be published. Required fields are marked *