In ilasm/codegen:
[mono.git] / mcs / ilasm / codegen / EventDef.cs
1 //
2 // Mono.ILASM.EventDef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All right reserved
8 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class EventDef : ICustomAttrTarget {
17
18                 private FeatureAttr attr;
19                 private string name;
20                 private ITypeRef type;
21                 private PEAPI.Event event_def;
22                 private bool is_resolved;
23                 private ArrayList customattr_list;
24
25                 private MethodRef addon;
26                 private MethodRef fire;
27                 private MethodRef other;
28                 private MethodRef removeon;
29
30                 public EventDef (FeatureAttr attr, ITypeRef type, string name)
31                 {
32                         this.attr = attr;
33                         this.name = name;
34                         this.type = type;
35                         is_resolved = false;
36                 }
37
38                 public void AddCustomAttribute (CustomAttr customattr)
39                 {
40                         if (customattr_list == null)
41                                 customattr_list = new ArrayList ();
42
43                         customattr_list.Add (customattr);
44                 }
45
46                 public PEAPI.Event Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
47                 {
48                         if (is_resolved)
49                                 return event_def;
50
51                         type.Resolve (code_gen);
52                         event_def = classdef.AddEvent (name, type.PeapiType);
53
54                         if ((attr & FeatureAttr.Rtspecialname) != 0)
55                                 event_def.SetRTSpecialName ();
56
57                         if ((attr & FeatureAttr.Specialname) != 0)
58                                 event_def.SetSpecialName ();
59                         
60                         if (customattr_list != null)
61                                 foreach (CustomAttr customattr in customattr_list)
62                                         customattr.AddTo (code_gen, event_def);
63
64                         is_resolved = true;
65
66                         return event_def;
67                 }
68
69                 public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
70                 {
71                         if (!is_resolved)
72                                 Resolve (code_gen, classdef);
73
74                         if (addon != null) {
75                                 addon.Resolve (code_gen);
76                                 event_def.AddAddon ((PEAPI.MethodDef) addon.PeapiMethod);
77                         }
78
79                         if (fire != null) {
80                                 fire.Resolve (code_gen);
81                                 event_def.AddFire ((PEAPI.MethodDef) fire.PeapiMethod);
82                         }
83
84                         if (other != null) {
85                                 other.Resolve (code_gen);
86                                 event_def.AddOther ((PEAPI.MethodDef) other.PeapiMethod);
87                         }
88
89                         if (removeon != null) {
90                                 removeon.Resolve (code_gen);
91                                 event_def.AddRemoveOn ((PEAPI.MethodDef) removeon.PeapiMethod);
92                         }
93                 }
94
95                 public void AddAddon (MethodRef method_ref)
96                 {
97                         addon = method_ref;
98                 }
99
100                 public void AddFire (MethodRef method_ref)
101                 {
102                         fire = method_ref;
103                 }
104
105                 public void AddOther (MethodRef method_ref)
106                 {
107                         other = method_ref;
108                 }
109
110                 public void AddRemoveon (MethodRef method_ref)
111                 {
112                         removeon = method_ref;
113                 }
114
115         }
116
117 }
118