23.5 Displaying Event Information

 <  Day Day Up  >  

You want to determine the events that a type supports within a module.


Technique

To enumerate all the supported events within a Type , call the GetEvents method, which returns an array of EventInfo objects. To determine the data type of the delegate that can bind and listen for this event, use the EventHandlerType property, which returns a Type . Most events allow an unlimited number of bound listeners. This technique is known as multicasting . If an event supports this technique, the IsMulticast property returns true :

 
 // get events curType = new TreeNode( "Events" ); foreach( EventInfo curEvent in t.GetEvents() ) {     string eventInfo = curEvent.Name;     eventInfo += " Delegate Type=" + curEvent.EventHandlerType;     curMember = new TreeNode( eventInfo );     curMember.Tag = curEvent;     curType.Nodes.Add( curMember ); } newNode.Nodes.Add( curType ); // continued... 

Comments

Events are specialized methods that invoke bound delegates when they are fired . When you create an event, the event is translated into a class, which contains member methods and overloaded operators to facilitate the addition and removal of event listeners called delegates . All this work occurs behind the scenes for the developer creating the event within the class and goes to show how well the event model within the .NET Framework is implemented.

In this recipe and the next , you will see overlap between the member type being discussed and an associated member type. As just mentioned, an event causes additional methods to be added to your class for event-listener addition and removal. If you view the output as a result of calling the GetMethods method defined in the Type class, you see these Methods even though they aren't visible when you create your application. We mention this point solely because if your application utilizes reflection, you realize that extra methods are created, which you might want to ignore based on your application design.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net