Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to create dynamic event handler for MEF component events using only attributes and custom EventArgs for decision making?

$
0
0

I have an application that is comprised of MEF components that are configured as a complete application at run time. The components have events that need to be reported to the main window's code. Since the components are loaded at runtime, I don't know, and don't have explicit code for, each of the component's events. How would I use a generic event handler in the main application that could use some attribute on a component class or method to determine the action to take when the event occurs? For example, if I have a OnButtonClick in two or more components, I want to use some common method to capture that event in the containing application and then act based on the source of the event (the specific MEF component that raised the event in the first place.)

I'm thinking that the delegate I use could have a custom EventArgs that contains properties such as method name, parameters, parameter types, etc. Then the event handler in the main app could examine those custom event args and use MEF catalog filtering to locate the method with the given name since it would be set as a custom attribute on the method itself.

Any help would be appreciated!


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>