3 // System.Reflection.Emit/EventBuilder.cs
6 // Paolo Molaro (lupus@ximian.com)
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
12 using System.Reflection;
13 using System.Reflection.Emit;
14 using System.Globalization;
15 using System.Runtime.CompilerServices;
16 using System.Runtime.InteropServices;
18 namespace System.Reflection.Emit {
19 public sealed class EventBuilder {
23 CustomAttributeBuilder[] cattrs;
24 MethodBuilder add_method;
25 MethodBuilder remove_method;
26 MethodBuilder raise_method;
27 MethodBuilder[] other_methods;
28 EventAttributes attrs;
31 internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
36 table_idx = get_next_table_index (this, 0x14, true);
39 internal int get_next_table_index (object obj, int table, bool inc) {
40 return typeb.get_next_table_index (obj, table, inc);
43 public void AddOtherMethod( MethodBuilder mdBuilder) {
44 if (mdBuilder == null)
45 throw new ArgumentNullException ("mdBuilder");
47 if (other_methods != null) {
48 MethodBuilder[] newv = new MethodBuilder [other_methods.Length + 1];
49 other_methods.CopyTo (newv, 0);
52 other_methods = new MethodBuilder [1];
54 other_methods [other_methods.Length - 1] = mdBuilder;
57 public EventToken GetEventToken () {
58 return new EventToken (0x14000000 | table_idx);
60 public void SetAddOnMethod( MethodBuilder mdBuilder) {
61 if (mdBuilder == null)
62 throw new ArgumentNullException ("mdBuilder");
64 add_method = mdBuilder;
66 public void SetRaiseMethod( MethodBuilder mdBuilder) {
67 if (mdBuilder == null)
68 throw new ArgumentNullException ("mdBuilder");
70 raise_method = mdBuilder;
72 public void SetRemoveOnMethod( MethodBuilder mdBuilder) {
73 if (mdBuilder == null)
74 throw new ArgumentNullException ("mdBuilder");
76 remove_method = mdBuilder;
79 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
80 if (customBuilder == null)
81 throw new ArgumentNullException ("customBuilder");
84 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
85 cattrs.CopyTo (new_array, 0);
86 new_array [cattrs.Length] = customBuilder;
89 cattrs = new CustomAttributeBuilder [1];
90 cattrs [0] = customBuilder;
93 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
95 throw new ArgumentNullException ("con");
96 if (binaryAttribute == null)
97 throw new ArgumentNullException ("binaryAttribute");
98 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
101 private void RejectIfCreated () {
102 if (typeb.is_created)
103 throw new InvalidOperationException ("Type definition of the method is complete.");