Creating Events in Mono.Cecil
-
15-01-2021 - |
Frage
I've been trying to create events with Mono.Cecil, but not sure how.
EventDefinition newEvent = new EventDefinition("newEvent",
Mono.Cecil.EventAttributes.None,
someRefToTheEventHandlerDelegate);
I'm stuck at the addon and removeon part. Please help me.
Lösung
You'll need to add the MethodDefinition for "add_newEvent" and "remove_newEvent" and assign them to the newEvent instance.
An easy way to learn how Cecil works and how it wants things to be set up is to:
1) compile what you want in an assembly (e.g. your event as you wish it);
2) load it with Mono.Cecil
3) use a debugger (MonoDevelop or VisualStudio will do) to see how things are populated;
4) codify the same into your application;
5) profit! ;-)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow