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