Wed Apr 3 19:46:00 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System / MonoType.cs
1 // System.MonoType
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 // Paolo Molaro (lupus@ximian.com)
5 //
6 // (C) 2001 Ximian, Inc.
7
8 using System.Reflection;
9 using System.Runtime.CompilerServices;
10 using System.Globalization;
11
12 namespace System
13 {
14         internal struct MonoTypeInfo {
15                 public string name;
16                 public string name_space;
17                 public Type parent;
18                 public Type etype;
19                 public Assembly assembly;
20                 public TypeAttributes attrs;
21                 public int rank;
22                 public bool isbyref;
23                 public bool ispointer;
24                 public bool isprimitive;
25         }
26
27         internal class MonoType : Type
28         {
29
30                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
31                 private static extern void type_from_obj (MonoType type, Object obj);
32                 
33                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
34                 private static extern void get_type_info (RuntimeTypeHandle type, out MonoTypeInfo info);
35
36                 [MonoTODO]
37                 internal MonoType (Object obj) {
38                         // this should not be used - lupus
39                         type_from_obj (this, obj);
40                         throw new NotImplementedException ();
41                 }
42
43                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
44                 private static extern TypeAttributes get_attributes (Type type);
45         
46                 protected override TypeAttributes GetAttributeFlagsImpl () {
47                         return get_attributes (this);
48                 }
49
50                 [MonoTODO]
51                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
52                         throw new NotImplementedException ();
53                 }
54
55                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
56                 public extern override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
57
58                 [MonoTODO]
59                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr) {
60                         throw new NotImplementedException ();
61                 }
62
63                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
64                 public extern override EventInfo[] GetEvents (BindingFlags bindingAttr);
65
66                 public override FieldInfo GetField( string name, BindingFlags bindingAttr) {
67                         //FIXME
68                         return null;
69                 }
70
71                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
72                 [MonoTODO]
73                 public extern override FieldInfo[] GetFields (BindingFlags bindingAttr);
74
75                 public override Type GetInterface (string name, bool ignoreCase) {
76                         throw new NotImplementedException ();
77                 }
78
79                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
80                 [MonoTODO]
81                 public extern override Type[] GetInterfaces();
82                 
83                 public override MemberInfo[] GetMembers( BindingFlags bindingAttr) {
84                         // FIXME
85                         throw new NotImplementedException ();
86                 }
87
88                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
89                 public extern override MethodInfo[] GetMethods (BindingFlags bindingAttr);
90
91                 protected override MethodInfo GetMethodImpl( string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
92                         // FIXME
93                         return null;
94                 }
95                 
96                 public override Type GetNestedType( string name, BindingFlags bindingAttr) {
97                         // FIXME
98                         return null;
99                 }
100
101                 public override Type[] GetNestedTypes (BindingFlags bindingAttr) {
102                         // FIXME
103                         return null;
104                 }
105
106                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
107                 public extern override PropertyInfo[] GetProperties( BindingFlags bindingAttr);
108                 
109                 protected override PropertyInfo GetPropertyImpl( string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
110                         // FIXME
111                         return null;
112                 }
113
114                 protected override bool HasElementTypeImpl () {
115                         return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
116                 }
117
118                 protected override bool IsArrayImpl () {
119                         return type_is_subtype_of (this, typeof (System.Array), false);
120                 }
121                 protected override bool IsByRefImpl () {
122                         MonoTypeInfo info;
123                         get_type_info (_impl, out info);
124                         return info.isbyref;
125                 }
126                 protected override bool IsCOMObjectImpl () {
127                         return false;
128                 }
129                 protected override bool IsPointerImpl () {
130                         MonoTypeInfo info;
131                         get_type_info (_impl, out info);
132                         return info.ispointer;
133                 }
134                 protected override bool IsPrimitiveImpl () {
135                         MonoTypeInfo info;
136                         get_type_info (_impl, out info);
137                         return info.isprimitive;
138                 }
139                 protected override bool IsValueTypeImpl () {
140                         return type_is_subtype_of (this, typeof (System.ValueType), false) &&
141                                 this != typeof (System.ValueType) &&
142                                 this != typeof (System.Enum);
143                 }
144                 
145                 public override object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) {
146                         // FIXME
147                         return null;
148                 }
149
150                 public override Type GetElementType()
151                 {
152                         MonoTypeInfo info;
153                         get_type_info (_impl, out info);
154                         return info.etype;
155                 }
156
157                 public override Type UnderlyingSystemType {
158                         get {
159                                 MonoTypeInfo info;
160                                 get_type_info (_impl, out info);
161                                 return info.etype;
162                         }
163                 }
164
165                 public override Assembly Assembly {
166                         get {
167                                 MonoTypeInfo info;
168                                 get_type_info (_impl, out info);
169                                 return info.assembly;
170                         }
171                 }
172
173                 public override string AssemblyQualifiedName {
174                         get {
175                                 return getFullName () + "," + Assembly.ToString ();
176                         }
177                 }
178
179                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
180                 private extern string getFullName();
181
182                 public override Type BaseType {
183                         get {
184                                 MonoTypeInfo info;
185                                 get_type_info (_impl, out info);
186                                 return info.parent;
187                         }
188                 }
189
190                 public override string FullName {
191                         get {
192                                 return getFullName ();
193                         }
194                 }
195
196                 public override Guid GUID {
197                         get {return Guid.Empty;}
198                 }
199
200                 public override bool IsDefined (Type attributeType, bool inherit)
201                 {
202                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
203                 }
204
205                 public override object[] GetCustomAttributes (bool inherit)
206                 {
207                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
208                 }
209
210                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
211                 {
212                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
213                 }
214
215                 public override MemberTypes MemberType {
216                         get {
217                                 return MemberTypes.TypeInfo;
218                         }
219                 }
220
221                 public override string Name {
222                         get {
223                                 MonoTypeInfo info;
224                                 get_type_info (_impl, out info);
225                                 return info.name;
226                         }
227                 }
228
229                 public override string Namespace {
230                         get {
231                                 MonoTypeInfo info;
232                                 get_type_info (_impl, out info);
233                                 return info.name_space;
234                         }
235                 }
236
237                 public override Module Module {
238                         get {
239                                 return null;
240                         }
241                 }
242
243                 public override Type ReflectedType {
244                         get {
245                                 return null;
246                         }
247                 }
248
249                 public override RuntimeTypeHandle TypeHandle {
250                         get {
251                                 return _impl;
252                         }
253                 }
254
255                 public override int GetArrayRank () {
256                         MonoTypeInfo info;
257                         get_type_info (_impl, out info);
258                         return info.rank;
259                 }
260         }
261 }