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