Add support for ToolsVersion and correctly build msbuild+xbuild assemblies
[mcs.git] / ilasm / codegen / EventDef.cs
blob66ba98614b9a3383946eb9a7151609539f5b4d9b
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 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class EventDef : ICustomAttrTarget {
18 private FeatureAttr attr;
19 private string name;
20 private BaseTypeRef type;
21 private PEAPI.Event event_def;
22 private bool is_resolved;
23 private ArrayList customattr_list;
25 private MethodRef addon;
26 private MethodRef fire;
27 private ArrayList other_list;
28 private MethodRef removeon;
30 public EventDef (FeatureAttr attr, BaseTypeRef type, string name)
32 this.attr = attr;
33 this.name = name;
34 this.type = type;
35 is_resolved = false;
38 public void AddCustomAttribute (CustomAttr customattr)
40 if (customattr_list == null)
41 customattr_list = new ArrayList ();
43 customattr_list.Add (customattr);
46 public PEAPI.Event Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
48 if (is_resolved)
49 return event_def;
51 type.Resolve (code_gen);
52 event_def = classdef.AddEvent (name, type.PeapiType);
54 if ((attr & FeatureAttr.Rtspecialname) != 0)
55 event_def.SetRTSpecialName ();
57 if ((attr & FeatureAttr.Specialname) != 0)
58 event_def.SetSpecialName ();
60 if (customattr_list != null)
61 foreach (CustomAttr customattr in customattr_list)
62 customattr.AddTo (code_gen, event_def);
64 is_resolved = true;
66 return event_def;
69 private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
71 PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
72 if (methoddef == null)
73 Report.Error (type + " method of event " + name + " not found");
74 return methoddef;
77 public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
79 if (!is_resolved)
80 Resolve (code_gen, classdef);
82 if (addon != null) {
83 addon.Resolve (code_gen);
84 event_def.AddAddon (AsMethodDef (addon.PeapiMethod, "addon"));
87 if (fire != null) {
88 fire.Resolve (code_gen);
89 event_def.AddFire (AsMethodDef (fire.PeapiMethod, "fire"));
92 if (other_list != null) {
93 foreach (MethodRef otherm in other_list) {
94 otherm.Resolve (code_gen);
95 event_def.AddOther (AsMethodDef (otherm.PeapiMethod, "other"));
99 if (removeon != null) {
100 removeon.Resolve (code_gen);
101 event_def.AddRemoveOn (AsMethodDef (removeon.PeapiMethod, "removeon"));
105 public void AddAddon (MethodRef method_ref)
107 addon = method_ref;
110 public void AddFire (MethodRef method_ref)
112 fire = method_ref;
115 public void AddOther (MethodRef method_ref)
117 if (other_list == null)
118 other_list = new ArrayList ();
119 other_list.Add (method_ref);
122 public void AddRemoveon (MethodRef method_ref)
124 removeon = method_ref;