EventBuilder.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // System.Reflection.Emit/EventBuilder.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. //
  7. // (C) 2001 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Reflection;
  11. using System.Reflection.Emit;
  12. using System.Globalization;
  13. using System.Runtime.CompilerServices;
  14. using System.Runtime.InteropServices;
  15. namespace System.Reflection.Emit {
  16. public sealed class EventBuilder {
  17. string name;
  18. Type type;
  19. TypeBuilder typeb;
  20. CustomAttributeBuilder[] cattrs;
  21. MethodBuilder add_method;
  22. MethodBuilder remove_method;
  23. MethodBuilder raise_method;
  24. MethodBuilder[] other_methods;
  25. EventAttributes attrs;
  26. int table_idx;
  27. internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
  28. name = eventName;
  29. attrs = eventAttrs;
  30. type = eventType;
  31. typeb = tb;
  32. table_idx = get_next_table_index (this, 0x14, true);
  33. }
  34. internal int get_next_table_index (object obj, int table, bool inc) {
  35. return typeb.get_next_table_index (obj, table, inc);
  36. }
  37. public void AddOtherMethod( MethodBuilder mdBuilder) {
  38. if (other_methods != null) {
  39. MethodBuilder[] newv = new MethodBuilder [other_methods.Length + 1];
  40. other_methods.CopyTo (newv, 0);
  41. other_methods = newv;
  42. } else {
  43. other_methods = new MethodBuilder [1];
  44. }
  45. other_methods [other_methods.Length - 1] = mdBuilder;
  46. }
  47. public EventToken GetEventToken () {
  48. return new EventToken (0x14000000 | table_idx);
  49. }
  50. public void SetAddOnMethod( MethodBuilder mdBuilder) {
  51. add_method = mdBuilder;
  52. }
  53. public void SetRaiseMethod( MethodBuilder mdBuilder) {
  54. raise_method = mdBuilder;
  55. }
  56. public void SetRemoveOnMethod( MethodBuilder mdBuilder) {
  57. remove_method = mdBuilder;
  58. }
  59. public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
  60. if (cattrs != null) {
  61. CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
  62. cattrs.CopyTo (new_array, 0);
  63. new_array [cattrs.Length] = customBuilder;
  64. cattrs = new_array;
  65. } else {
  66. cattrs = new CustomAttributeBuilder [1];
  67. cattrs [0] = customBuilder;
  68. }
  69. }
  70. public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
  71. SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
  72. }
  73. }
  74. }