In ilasm/tests:
[mono.git] / mcs / ilasm / codegen / PropertyDef.cs
1 //
2 // Mono.ILASM.PropertyDef
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 PropertyDef : ICustomAttrTarget {
17
18                 private FeatureAttr attr;
19                 private string name;
20                 private ITypeRef type;
21                 private ArrayList arg_list;
22                 private PEAPI.Property prop_def;
23                 private bool is_resolved;
24                 private ArrayList customattr_list;
25
26                 private MethodRef _get;
27                 private MethodRef _set;
28                 private MethodRef other;
29                 private PEAPI.Constant init_value;
30
31                 public PropertyDef (FeatureAttr attr, ITypeRef type, string name, ArrayList arg_list)
32                 {
33                         this.attr = attr;
34                         this.name = name;
35                         this.type = type;
36                         this.arg_list = arg_list;
37                         is_resolved = false;
38                 }
39
40                 public void AddCustomAttribute (CustomAttr customattr)
41                 {
42                         if (customattr_list == null)
43                                 customattr_list = new ArrayList ();
44
45                         customattr_list.Add (customattr);
46                 }
47
48                 public PEAPI.Property Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
49                 {
50                         if (is_resolved)
51                                 return prop_def;
52
53                         PEAPI.Type[] type_list = new PEAPI.Type[arg_list.Count];
54
55                         for (int i=0; i<type_list.Length; i++) {
56                                 ITypeRef arg_type = (ITypeRef) arg_list[i];
57                                 arg_type.Resolve (code_gen);
58                                 type_list[i] = arg_type.PeapiType;
59                         }
60
61                         type.Resolve (code_gen);
62                         prop_def = classdef.AddProperty (name, type.PeapiType, type_list);
63
64                         if ((attr & FeatureAttr.Rtspecialname) != 0)
65                                 prop_def.SetRTSpecialName ();
66
67                         if ((attr & FeatureAttr.Specialname) != 0)
68                                 prop_def.SetSpecialName ();
69
70                         prop_def.SetInstance ((attr & FeatureAttr.Instance) != 0);
71
72                         if (customattr_list != null)
73                                 foreach (CustomAttr customattr in customattr_list)
74                                         customattr.AddTo (code_gen, prop_def);
75
76
77                         is_resolved = true;
78
79                         return prop_def;
80                 }
81
82                 public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
83                 {
84                         if (!is_resolved)
85                                 Resolve (code_gen, classdef);
86
87                         if (_get != null) {
88                                 _get.Resolve (code_gen);
89                                 prop_def.AddGetter ((PEAPI.MethodDef) _get.PeapiMethod);
90                         }
91
92                         if (_set != null) {
93                                 _set.Resolve (code_gen);
94                                 prop_def.AddSetter ((PEAPI.MethodDef) _set.PeapiMethod);
95                         }
96
97                         if (other != null) {
98                                 other.Resolve (code_gen);
99                                 prop_def.AddOther ((PEAPI.MethodDef) other.PeapiMethod);
100                         }
101
102                         if (init_value != null)
103                                 prop_def.AddInitValue (init_value);
104                 }
105
106                 public void AddGet (MethodRef _get)
107                 {
108                         this._get = _get;
109                 }
110
111                 public void AddSet (MethodRef _set)
112                 {
113                         this._set = _set;
114                 }
115
116                 public void AddOther (MethodRef other)
117                 {
118                         this.other = other;
119                 }
120
121                 public void AddInitValue (PEAPI.Constant init_value)
122                 {
123                         this.init_value = init_value;
124                 }
125         }
126
127 }
128