c# - Casting and Types Question -


I am bubbling events in my application and therefore using the bubble event method, since this method handled all kinds of bubble events They have a switch, or if to determine which type of event we are dealing with, I was wondering if I could create different versions of the Event Arrogs class and get around this. So explain to me, say that I have two types of events called different X and Y, I create new event ARGs classes for these two incidents because they store different types of information.

public class events rrxx: events public class event events: events@rgbuelwyven

Then when I come from anywhere in my application, then I will be one of two event AGR types I can also pass, so ..

  EventArgsX Fox = New EventArgsX (); RaiseBubbleEvent (zero, foox);  

or

  EventAgargacyFoo = new eventArshji (); RaiseBubbleEvent (zero, fooy);  

Then the OnBubbleEvent method picks up, which signatures overbride onbill events (object source, eventArgse E)

I can not now overload this method as an override There is a place, so I thought what I could do to handle it was another way with surcharge, so

  safe override OnBubbleEvent (Object Source, EventArgs e) {DoStuff ( E); } Private Zero DoStuff (EventArgsY Args) {} Private Zero DoStuff (EventArgsX args) {}  

But the problem is that EventArgs is the EventArgs type in the OnBubbleEvent method of calling Although we do not keep this information, we do not know about it. So how do I return it to my actual type of call method?

Many thanks, hope you can help me with this, it seems really easy as something can disappear or it can not be done now

Any ideas ??

It's easy:

Secure Override OnBall Event (object source, EventAGRS E) {if (E EventArgSX) DUSTF (EventAgGSX) E); And if (e is EventArgsY) DoStuff ((EventArgsY) e); }

This, kissing, is not very expandable. If you are planning on adding more event types, then you can try:

  Public Intangible Class EventArgsBase: EventArgs {Public Abstract Zero Bubble (IEventBubbler eb); } Public Interface IEventBubbler {Bubble (EventArgsX East); Bubble (EventGCCI); } Public Segment EventArgsX: EventArgsBase {Public Virtual Zune Bubble (IEventBubbler EB) {eb.Bubble (this); }} Public Sector EventArgsY: EventArgsBase {Public Virtual Zune Bubble (IEventBubbler EB) {eb.Bubble (this); }}  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -