EventBuilder.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. //
  24. // System.Reflection.Emit/EventBuilder.cs
  25. //
  26. // Author:
  27. // Paolo Molaro ([email protected])
  28. //
  29. // (C) 2001 Ximian, Inc. http://www.ximian.com
  30. //
  31. using System;
  32. using System.Reflection;
  33. using System.Reflection.Emit;
  34. using System.Globalization;
  35. using System.Runtime.CompilerServices;
  36. using System.Runtime.InteropServices;
  37. namespace System.Reflection.Emit {
  38. [ComVisible (true)]
  39. [ComDefaultInterface (typeof (_EventBuilder))]
  40. [ClassInterface (ClassInterfaceType.None)]
  41. public sealed class EventBuilder : _EventBuilder {
  42. #pragma warning disable 169, 414
  43. internal string name;
  44. Type type;
  45. TypeBuilder typeb;
  46. CustomAttributeBuilder[] cattrs;
  47. internal MethodBuilder add_method;
  48. internal MethodBuilder remove_method;
  49. internal MethodBuilder raise_method;
  50. internal MethodBuilder[] other_methods;
  51. internal EventAttributes attrs;
  52. int table_idx;
  53. #pragma warning restore 169, 414
  54. internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
  55. name = eventName;
  56. attrs = eventAttrs;
  57. type = eventType;
  58. typeb = tb;
  59. table_idx = get_next_table_index (this, 0x14, true);
  60. }
  61. internal int get_next_table_index (object obj, int table, bool inc) {
  62. return typeb.get_next_table_index (obj, table, inc);
  63. }
  64. public void AddOtherMethod( MethodBuilder mdBuilder) {
  65. if (mdBuilder == null)
  66. throw new ArgumentNullException ("mdBuilder");
  67. RejectIfCreated ();
  68. if (other_methods != null) {
  69. MethodBuilder[] newv = new MethodBuilder [other_methods.Length + 1];
  70. other_methods.CopyTo (newv, 0);
  71. other_methods = newv;
  72. } else {
  73. other_methods = new MethodBuilder [1];
  74. }
  75. other_methods [other_methods.Length - 1] = mdBuilder;
  76. }
  77. public EventToken GetEventToken () {
  78. return new EventToken (0x14000000 | table_idx);
  79. }
  80. public void SetAddOnMethod( MethodBuilder mdBuilder) {
  81. if (mdBuilder == null)
  82. throw new ArgumentNullException ("mdBuilder");
  83. RejectIfCreated ();
  84. add_method = mdBuilder;
  85. }
  86. public void SetRaiseMethod( MethodBuilder mdBuilder) {
  87. if (mdBuilder == null)
  88. throw new ArgumentNullException ("mdBuilder");
  89. RejectIfCreated ();
  90. raise_method = mdBuilder;
  91. }
  92. public void SetRemoveOnMethod( MethodBuilder mdBuilder) {
  93. if (mdBuilder == null)
  94. throw new ArgumentNullException ("mdBuilder");
  95. RejectIfCreated ();
  96. remove_method = mdBuilder;
  97. }
  98. public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
  99. if (customBuilder == null)
  100. throw new ArgumentNullException ("customBuilder");
  101. RejectIfCreated ();
  102. string attrname = customBuilder.Ctor.ReflectedType.FullName;
  103. if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
  104. attrs |= EventAttributes.SpecialName;
  105. return;
  106. }
  107. if (cattrs != null) {
  108. CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
  109. cattrs.CopyTo (new_array, 0);
  110. new_array [cattrs.Length] = customBuilder;
  111. cattrs = new_array;
  112. } else {
  113. cattrs = new CustomAttributeBuilder [1];
  114. cattrs [0] = customBuilder;
  115. }
  116. }
  117. [ComVisible (true)]
  118. public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
  119. if (con == null)
  120. throw new ArgumentNullException ("con");
  121. if (binaryAttribute == null)
  122. throw new ArgumentNullException ("binaryAttribute");
  123. SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
  124. }
  125. private void RejectIfCreated () {
  126. if (typeb.is_created)
  127. throw new InvalidOperationException ("Type definition of the method is complete.");
  128. }
  129. void _EventBuilder.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  130. {
  131. throw new NotImplementedException ();
  132. }
  133. void _EventBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. void _EventBuilder.GetTypeInfoCount (out uint pcTInfo)
  138. {
  139. throw new NotImplementedException ();
  140. }
  141. void _EventBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  142. {
  143. throw new NotImplementedException ();
  144. }
  145. }
  146. }