The Labs \ Source Viewer \ SSCLI \ System.Reflection.Emit \ EventBuilder

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** Class:  EventBuilder
  18. **
  19. **
  20. ** Eventbuilder is for client to define eevnts for a class
  21. **
  22. **
  23. ===========================================================*/
  24. namespace System.Reflection.Emit
  25. {
  26.    
  27.     using System;
  28.     using System.Reflection;
  29.     using System.Security.Permissions;
  30.     using System.Runtime.InteropServices;
  31.    
  32.     //
  33.     // A EventBuilder is always associated with a TypeBuilder. The TypeBuilder.DefineEvent
  34.     // method will return a new EventBuilder to a client.
  35.     //
  36.     [HostProtection(MayLeakOnAbort = true)]
  37.     [ClassInterface(ClassInterfaceType.None)]
  38.     [ComDefaultInterface(typeof(_EventBuilder))]
  39.     [System.Runtime.InteropServices.ComVisible(true)]
  40.     public sealed class EventBuilder : _EventBuilder
  41.     {
  42.        
  43.         // Make a private constructor so these cannot be constructed externally.
  44.         private EventBuilder()
  45.         {
  46.         }
  47.        
  48.         // Constructs a EventBuilder.
  49.         //
  50.             // the module containing this EventBuilder
  51.             // Event name
  52.             // event attribute such as Public, Private, and Protected defined above
  53.             // event type
  54.             // containing type
  55.         internal EventBuilder(Module mod, string name, EventAttributes attr, int eventType, TypeBuilder type, EventToken evToken)
  56.         {
  57.             m_name = name;
  58.             m_module = mod;
  59.             m_attributes = attr;
  60.             m_evToken = evToken;
  61.             m_type = type;
  62.         }
  63.        
  64.         // Return the Token for this event within the TypeBuilder that the
  65.         // event is defined within.
  66.         public EventToken GetEventToken()
  67.         {
  68.             return m_evToken;
  69.         }
  70.        
  71.        
  72.         public void SetAddOnMethod(MethodBuilder mdBuilder)
  73.         {
  74.             if (mdBuilder == null) {
  75.                 throw new ArgumentNullException("mdBuilder");
  76.             }
  77.            
  78.             m_type.ThrowIfCreated();
  79.             TypeBuilder.InternalDefineMethodSemantics(m_module, m_evToken.Token, MethodSemanticsAttributes.AddOn, mdBuilder.GetToken().Token);
  80.         }
  81.        
  82.        
  83.         public void SetRemoveOnMethod(MethodBuilder mdBuilder)
  84.         {
  85.             if (mdBuilder == null) {
  86.                 throw new ArgumentNullException("mdBuilder");
  87.             }
  88.             m_type.ThrowIfCreated();
  89.             TypeBuilder.InternalDefineMethodSemantics(m_module, m_evToken.Token, MethodSemanticsAttributes.RemoveOn, mdBuilder.GetToken().Token);
  90.         }
  91.        
  92.        
  93.         public void SetRaiseMethod(MethodBuilder mdBuilder)
  94.         {
  95.             if (mdBuilder == null) {
  96.                 throw new ArgumentNullException("mdBuilder");
  97.             }
  98.             m_type.ThrowIfCreated();
  99.             TypeBuilder.InternalDefineMethodSemantics(m_module, m_evToken.Token, MethodSemanticsAttributes.Fire, mdBuilder.GetToken().Token);
  100.         }
  101.        
  102.        
  103.         public void AddOtherMethod(MethodBuilder mdBuilder)
  104.         {
  105.             if (mdBuilder == null) {
  106.                 throw new ArgumentNullException("mdBuilder");
  107.             }
  108.            
  109.             m_type.ThrowIfCreated();
  110.             TypeBuilder.InternalDefineMethodSemantics(m_module, m_evToken.Token, MethodSemanticsAttributes.Other, mdBuilder.GetToken().Token);
  111.         }
  112.        
  113.         // Use this function if client decides to form the custom attribute blob themselves
  114.         [System.Runtime.InteropServices.ComVisible(true)]
  115.         public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
  116.         {
  117.             if (con == null)
  118.                 throw new ArgumentNullException("con");
  119.             if (binaryAttribute == null)
  120.                 throw new ArgumentNullException("binaryAttribute");
  121.             m_type.ThrowIfCreated();
  122.            
  123.             TypeBuilder.InternalCreateCustomAttribute(m_evToken.Token, ((ModuleBuilder)m_module).GetConstructorToken(con).Token, binaryAttribute, m_module, false);
  124.         }
  125.        
  126.         // Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder
  127.         public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
  128.         {
  129.             if (customBuilder == null) {
  130.                 throw new ArgumentNullException("customBuilder");
  131.             }
  132.             m_type.ThrowIfCreated();
  133.             customBuilder.CreateCustomAttribute((ModuleBuilder)m_module, m_evToken.Token);
  134.         }
  135.        
  136.         void _EventBuilder.GetTypeInfoCount(out uint pcTInfo)
  137.         {
  138.             throw new NotImplementedException();
  139.         }
  140.        
  141.         void _EventBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
  142.         {
  143.             throw new NotImplementedException();
  144.         }
  145.        
  146.         void _EventBuilder.GetIDsOfNames(        [In()]
  147. ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  148.         {
  149.             throw new NotImplementedException();
  150.         }
  151.        
  152.         void _EventBuilder.Invoke(uint dispIdMember,         [In()]
  153. ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  154.         {
  155.             throw new NotImplementedException();
  156.         }
  157.        
  158.        
  159.         // These are package private so that TypeBuilder can access them.
  160.         private string m_name;
  161.         // The name of the event
  162.         private EventToken m_evToken;
  163.         // The token of this event
  164.         private Module m_module;
  165.         private EventAttributes m_attributes;
  166.         private TypeBuilder m_type;
  167.     }
  168.    
  169.    
  170.    
  171.    
  172. }

Developer Fusion