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