2 // Mono.ILASM.PropertyDef
5 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // (C) 2003 Jackson Harper, All right reserved
12 using System
.Collections
;
14 namespace Mono
.ILASM
{
16 public class PropertyDef
: ICustomAttrTarget
{
18 private FeatureAttr attr
;
20 private BaseTypeRef type
;
21 private ArrayList arg_list
;
22 private PEAPI
.Property prop_def
;
23 private bool is_resolved
;
24 private ArrayList customattr_list
;
26 private MethodRef _get
;
27 private MethodRef _set
;
28 private ArrayList other_list
;
29 private PEAPI
.Constant init_value
;
31 public PropertyDef (FeatureAttr attr
, BaseTypeRef type
, string name
, ArrayList arg_list
)
36 this.arg_list
= arg_list
;
40 public void AddCustomAttribute (CustomAttr customattr
)
42 if (customattr_list
== null)
43 customattr_list
= new ArrayList ();
45 customattr_list
.Add (customattr
);
48 public PEAPI
.Property
Resolve (CodeGen code_gen
, PEAPI
.ClassDef classdef
)
53 PEAPI
.Type
[] type_list
= new PEAPI
.Type
[arg_list
.Count
];
55 for (int i
=0; i
<type_list
.Length
; i
++) {
56 BaseTypeRef arg_type
= (BaseTypeRef
) arg_list
[i
];
57 arg_type
.Resolve (code_gen
);
58 type_list
[i
] = arg_type
.PeapiType
;
61 type
.Resolve (code_gen
);
62 prop_def
= classdef
.AddProperty (name
, type
.PeapiType
, type_list
);
64 if ((attr
& FeatureAttr
.Rtspecialname
) != 0)
65 prop_def
.SetRTSpecialName ();
67 if ((attr
& FeatureAttr
.Specialname
) != 0)
68 prop_def
.SetSpecialName ();
70 prop_def
.SetInstance ((attr
& FeatureAttr
.Instance
) != 0);
72 if (customattr_list
!= null)
73 foreach (CustomAttr customattr
in customattr_list
)
74 customattr
.AddTo (code_gen
, prop_def
);
82 private PEAPI
.MethodDef
AsMethodDef (PEAPI
.Method method
, string type
)
84 PEAPI
.MethodDef methoddef
= method
as PEAPI
.MethodDef
;
85 if (methoddef
== null)
86 Report
.Error (type
+ " method of property " + name
+ " not found");
90 public void Define (CodeGen code_gen
, PEAPI
.ClassDef classdef
)
93 Resolve (code_gen
, classdef
);
96 _get
.Resolve (code_gen
);
97 prop_def
.AddGetter (AsMethodDef (_get
.PeapiMethod
, "get"));
101 _set
.Resolve (code_gen
);
102 prop_def
.AddSetter (AsMethodDef (_set
.PeapiMethod
, "set"));
105 if (other_list
!= null) {
106 foreach (MethodRef otherm
in other_list
) {
107 otherm
.Resolve (code_gen
);
108 prop_def
.AddOther (AsMethodDef (otherm
.PeapiMethod
, "other"));
112 if (init_value
!= null)
113 prop_def
.AddInitValue (init_value
);
116 public void AddGet (MethodRef _get
)
121 public void AddSet (MethodRef _set
)
126 public void AddOther (MethodRef other
)
128 if (other_list
== null)
129 other_list
= new ArrayList ();
130 other_list
.Add (other
);
133 public void AddInitValue (PEAPI
.Constant init_value
)
135 this.init_value
= init_value
;