Simplify the creation of events and their call

Andriy

New member
Joined
Apr 18, 2019
Messages
1
Programming Experience
3-5
When you creating events, it takes a lot of time to writing service code.
You need:
class EventArgs - for data
class TODO - which doing some manipulation of data (it contains delegate, event and TODOMethod -for event calling)
and
MethodHandler(object sender, EventArgs e), which subscribed on event and will been called when if statment == true e.c.
It could be simplified, like async/await. This is must be some simple expression like
MethodHandler(some type of data) => when counter = 100;
And it statement will create all service code: EventArgs, TODO, MethodHandler()
 
I think that you're asking a question but I'm not sure. Firstly, you don't need to define your own delegate. You either use the EventHandler delegate if your event requires no data or the EventHandler<TEventArgs> if your event does require data.
C#:
public event EventHandler EventWithoutData;
public event EventHandler<EventArgs> EventWithData;
You should use an existing class that inherits EventArgs if you can but, if you need a custom class, you really have no choice but to create that class yourself. A separate class couldn't be generated by a snippet in the class that the event is a member of and you'd still have to add the properties yourself anyway. You could write a code snippet that generated the event declaration and the definition of the method that raises that event.
 
Back
Top Bottom