Merge System/MonoType.cs into ReferenceSources/RuntimeType.cs, use th… (#3045)
[mono.git] / mcs / class / corlib / ReferenceSources / RuntimeType.cs
1 //
2 // RuntimeType.cs
3 //
4 // Authors:
5 //      Marek Safar  <marek.safar@gmail.com>
6 //
7 // Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.Reflection;
30 using System.Runtime.CompilerServices;
31 using System.Threading;
32 using System.Collections.Generic;
33 using System.Runtime.InteropServices;
34 using System.Globalization;
35 #if MONO_COM
36 using System.Reflection.Emit;
37 #endif
38 using System.Diagnostics.Contracts;
39 using System.Security;
40 using System.Runtime.Serialization;
41
42 namespace System
43 {
44         // Contains information about the type which is expensive to compute
45         [StructLayout (LayoutKind.Sequential)]
46         internal class MonoTypeInfo {
47                 // this is the displayed form: special characters
48                 // ,+*&*[]\ in the identifier portions of the names
49                 // have been escaped with a leading backslash (\)
50                 public string full_name;
51                 public MonoCMethod default_ctor;
52         }
53
54         [StructLayout (LayoutKind.Sequential)]
55         partial class RuntimeType
56         {
57                 [NonSerialized]
58                 MonoTypeInfo type_info;
59
60                 internal Object GenericCache;
61
62                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
63                 private static extern void type_from_obj (RuntimeType type, Object obj);
64
65                 internal RuntimeType (Object obj)
66                 {
67                         // this should not be used - lupus
68                         type_from_obj (this, obj);
69
70                         throw new NotImplementedException ();
71                 }
72
73                 internal MonoCMethod GetDefaultConstructor ()
74                 {
75                         MonoCMethod ctor = null;
76
77                         if (type_info == null)
78                                 type_info = new MonoTypeInfo ();
79                         else
80                                 ctor = type_info.default_ctor;
81
82                         if (ctor == null) {
83                                 var ctors = GetConstructors (BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
84
85                                 for (int i = 0; i < ctors.Length; ++i) {
86                                         if (ctors [i].GetParametersCount () == 0) {
87                                                 type_info.default_ctor = ctor = (MonoCMethod) ctors [i];
88                                                 break;
89                                         }
90                                 }
91                         }
92
93                         return ctor;
94                 }
95
96                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
97                 extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
98
99                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
100                 extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
101
102                 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
103                 {
104                         if (fromNoninstanciated == null)
105                                 throw new ArgumentNullException ("fromNoninstanciated");
106                         return GetCorrespondingInflatedMethod (fromNoninstanciated);
107                 }
108
109                 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
110                 {
111                         if (fromNoninstanciated == null)
112                                 throw new ArgumentNullException ("fromNoninstanciated");
113                         return GetCorrespondingInflatedConstructor (fromNoninstanciated);
114                 }
115
116                 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
117                 {
118                         /* create sensible flags from given FieldInfo */
119                         BindingFlags flags = fromNoninstanciated.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
120                         flags |= fromNoninstanciated.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
121                         return GetField (fromNoninstanciated.Name, flags);
122                 }
123
124                 string GetDefaultMemberName ()
125                 {
126                         object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
127                         return att.Length != 0 ? ((DefaultMemberAttribute) att [0]).MemberName : null;
128                 }
129
130                 RuntimeConstructorInfo m_serializationCtor;
131                 internal RuntimeConstructorInfo GetSerializationCtor()
132                 {
133                         if (m_serializationCtor == null) {
134                                 var s_SICtorParamTypes = new Type[] { typeof(SerializationInfo), typeof(StreamingContext) };
135
136                                 m_serializationCtor = GetConstructor(
137                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
138                                         null,
139                                         CallingConventions.Any,
140                                         s_SICtorParamTypes,
141                                         null) as RuntimeConstructorInfo;
142                         }
143
144                         return m_serializationCtor;
145                 }
146
147                 internal Object CreateInstanceSlow(bool publicOnly, bool skipCheckThis, bool fillCache, ref StackCrawlMark stackMark)
148                 {
149                         bool bNeedSecurityCheck = true;
150                         bool bCanBeCached = false;
151                         bool bSecurityCheckOff = false;
152
153                         if (!skipCheckThis)
154                                 CreateInstanceCheckThis();
155
156                         if (!fillCache)
157                                 bSecurityCheckOff = true;
158
159                         return CreateInstanceMono (!publicOnly);
160                 }
161
162                 object CreateInstanceMono (bool nonPublic)
163                 {
164                         var ctor = GetDefaultConstructor ();
165                         if (!nonPublic && ctor != null && !ctor.IsPublic) {
166                                 ctor = null;
167                         }
168
169                         if (ctor == null) {
170                                 Type elementType = this.GetRootElementType();
171                                 if (ReferenceEquals (elementType, typeof (TypedReference)) || ReferenceEquals (elementType, typeof (RuntimeArgumentHandle)))
172                                         throw new NotSupportedException (Environment.GetResourceString ("NotSupported_ContainsStackPtr"));
173
174                                 if (IsValueType)
175                                         return CreateInstanceInternal (this);
176
177                                 throw new MissingMethodException (Locale.GetText ("Default constructor not found for type " + FullName));
178                         }
179
180                         // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance
181                         if (IsAbstract) {
182                                 throw new MissingMethodException (Locale.GetText ("Cannot create an abstract class '{0}'.", FullName));
183                         }
184
185                         return ctor.InternalInvoke (null, null);
186                 }
187
188                 internal Object CheckValue (Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
189                 {
190                         bool failed = false;
191                         var res = TryConvertToType (value, ref failed);
192                         if (!failed)
193                                 return res;
194
195                         if ((invokeAttr & BindingFlags.ExactBinding) == BindingFlags.ExactBinding)
196                                 throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
197
198                         if (binder != null && binder != Type.DefaultBinder)
199                                 return binder.ChangeType (value, this, culture);
200
201                         throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
202                 }
203
204                 object TryConvertToType (object value, ref bool failed)
205                 {
206                         if (IsInstanceOfType (value)) {
207                                 return value;
208                         }
209
210                         if (IsByRef) {
211                                 var elementType = GetElementType ();
212                                 if (value == null || elementType.IsInstanceOfType (value)) {
213                                         return value;
214                                 }
215                         }
216
217                         if (value == null)
218                                 return value;
219
220                         if (IsEnum) {
221                                 var type = Enum.GetUnderlyingType (this);
222                                 if (type == value.GetType ())
223                                         return value;
224                                 var res = IsConvertibleToPrimitiveType (value, this);
225                                 if (res != null)
226                                         return res;
227                         } else if (IsPrimitive) {
228                                 var res = IsConvertibleToPrimitiveType (value, this);
229                                 if (res != null)
230                                         return res;
231                         } else if (IsPointer) {
232                                 var vtype = value.GetType ();
233                                 if (vtype == typeof (IntPtr) || vtype == typeof (UIntPtr))
234                                         return value;
235                         }
236
237                         failed = true;
238                         return null;
239                 }
240
241                 // Binder uses some incompatible conversion rules. For example
242                 // int value cannot be used with decimal parameter but in other
243                 // ways it's more flexible than normal convertor, for example
244                 // long value can be used with int based enum
245                 static object IsConvertibleToPrimitiveType (object value, Type targetType)
246                 {
247                         var type = value.GetType ();
248                         if (type.IsEnum) {
249                                 type = Enum.GetUnderlyingType (type);
250                                 if (type == targetType)
251                                         return value;
252                         }
253
254                         var from = Type.GetTypeCode (type);
255                         var to = Type.GetTypeCode (targetType);
256
257                         switch (to) {
258                                 case TypeCode.Char:
259                                         switch (from) {
260                                                 case TypeCode.Byte:
261                                                         return (Char) (Byte) value;
262                                                 case TypeCode.UInt16:
263                                                         return value;
264                                         }
265                                         break;
266                                 case TypeCode.Int16:
267                                         switch (from) {
268                                                 case TypeCode.Byte:
269                                                         return (Int16) (Byte) value;
270                                                 case TypeCode.SByte:
271                                                         return (Int16) (SByte) value;
272                                         }
273                                         break;
274                                 case TypeCode.UInt16:
275                                         switch (from) {
276                                                 case TypeCode.Byte:
277                                                         return (UInt16) (Byte) value;
278                                                 case TypeCode.Char:
279                                                         return value;
280                                         }
281                                         break;
282                                 case TypeCode.Int32:
283                                         switch (from) {
284                                                 case TypeCode.Byte:
285                                                         return (Int32) (Byte) value;
286                                                 case TypeCode.SByte:
287                                                         return (Int32) (SByte) value;
288                                                 case TypeCode.Char:
289                                                         return (Int32) (Char) value;
290                                                 case TypeCode.Int16:
291                                                         return (Int32) (Int16) value;
292                                                 case TypeCode.UInt16:
293                                                         return (Int32) (UInt16) value;
294                                         }
295                                         break;
296                                 case TypeCode.UInt32:
297                                         switch (from) {
298                                                 case TypeCode.Byte:
299                                                         return (UInt32) (Byte) value;
300                                                 case TypeCode.Char:
301                                                         return (UInt32) (Char) value;
302                                                 case TypeCode.UInt16:
303                                                         return (UInt32) (UInt16) value;
304                                         }
305                                         break;
306                                 case TypeCode.Int64:
307                                         switch (from) {
308                                                 case TypeCode.Byte:
309                                                         return (Int64) (Byte) value;
310                                                 case TypeCode.SByte:
311                                                         return (Int64) (SByte) value;
312                                                 case TypeCode.Int16:
313                                                         return (Int64) (Int16) value;
314                                                 case TypeCode.Char:
315                                                         return (Int64) (Char) value;
316                                                 case TypeCode.UInt16:
317                                                         return (Int64) (UInt16) value;
318                                                 case TypeCode.Int32:
319                                                         return (Int64) (Int32) value;
320                                                 case TypeCode.UInt32:
321                                                         return (Int64) (UInt32) value;
322                                         }
323                                         break;
324                                 case TypeCode.UInt64:
325                                         switch (from) {
326                                                 case TypeCode.Byte:
327                                                         return (UInt64) (Byte) value;
328                                                 case TypeCode.Char:
329                                                         return (UInt64) (Char) value;
330                                                 case TypeCode.UInt16:
331                                                         return (UInt64) (UInt16) value;
332                                                 case TypeCode.UInt32:
333                                                         return (UInt64) (UInt32) value;
334                                         }
335                                         break;
336                                 case TypeCode.Single:
337                                         switch (from) {
338                                                 case TypeCode.Byte:
339                                                         return (Single) (Byte) value;
340                                                 case TypeCode.SByte:
341                                                         return (Single) (SByte) value;
342                                                 case TypeCode.Int16:
343                                                         return (Single) (Int16) value;
344                                                 case TypeCode.Char:
345                                                         return (Single) (Char) value;
346                                                 case TypeCode.UInt16:
347                                                         return (Single) (UInt16) value;
348                                                 case TypeCode.Int32:
349                                                         return (Single) (Int32) value;
350                                                 case TypeCode.UInt32:
351                                                         return (Single) (UInt32) value;
352                                                 case TypeCode.Int64:
353                                                         return (Single) (Int64) value;
354                                                 case TypeCode.UInt64:
355                                                         return (Single) (UInt64) value;
356                                         }
357                                         break;
358                                 case TypeCode.Double:
359                                         switch (from) {
360                                                 case TypeCode.Byte:
361                                                         return (Double) (Byte) value;
362                                                 case TypeCode.SByte:
363                                                         return (Double) (SByte) value;
364                                                 case TypeCode.Char:
365                                                         return (Double) (Char) value;
366                                                 case TypeCode.Int16:
367                                                         return (Double) (Int16) value;
368                                                 case TypeCode.UInt16:
369                                                         return (Double) (UInt16) value;
370                                                 case TypeCode.Int32:
371                                                         return (Double) (Int32) value;
372                                                 case TypeCode.UInt32:
373                                                         return (Double) (UInt32) value;
374                                                 case TypeCode.Int64:
375                                                         return (Double) (Int64) value;
376                                                 case TypeCode.UInt64:
377                                                         return (Double) (UInt64) value;
378                                                 case TypeCode.Single:
379                                                         return (Double) (Single) value;
380                                         }
381                                         break;
382                         }
383
384                         // Everything else is rejected
385                         return null;
386                 }
387
388                 string GetCachedName (TypeNameKind kind)
389                 {
390                         switch (kind) {
391                         case TypeNameKind.SerializationName:
392                                 return ToString ();
393                         default:
394                                 throw new NotImplementedException ();
395                         }
396                 }
397
398                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
399                 extern Type make_array_type (int rank);
400
401                 public override Type MakeArrayType ()
402                 {
403                         return make_array_type (0);
404                 }
405
406                 public override Type MakeArrayType (int rank)
407                 {
408                         if (rank < 1 || rank > 255)
409                                 throw new IndexOutOfRangeException ();
410                         return make_array_type (rank);
411                 }
412
413                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
414                 extern Type make_byref_type ();
415
416                 public override Type MakeByRefType ()
417                 {
418                         if (IsByRef)
419                                 throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
420                         return make_byref_type ();
421                 }
422
423                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
424                 static extern Type MakePointerType (Type type);
425
426                 public override Type MakePointerType ()
427                 {
428                         return MakePointerType (this);
429                 }
430
431                 public override StructLayoutAttribute StructLayoutAttribute {
432                         get {
433                                 return StructLayoutAttribute.GetCustomAttribute (this);
434                         }
435                 }
436
437                 public override bool ContainsGenericParameters {
438                         get {
439                                 if (IsGenericParameter)
440                                         return true;
441
442                                 if (IsGenericType) {
443                                         foreach (Type arg in GetGenericArguments ())
444                                                 if (arg.ContainsGenericParameters)
445                                                         return true;
446                                 }
447
448                                 if (HasElementType)
449                                         return GetElementType ().ContainsGenericParameters;
450
451                                 return false;
452                         }
453                 }
454
455                 public override Type[] GetGenericParameterConstraints()
456                 {
457                         if (!IsGenericParameter)
458                                 throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
459                         Contract.EndContractBlock();
460
461                         Type[] constraints = GetGenericParameterConstraints_impl ();
462
463                         if (constraints == null)
464                                 constraints = EmptyArray<Type>.Value;
465
466                         return constraints;
467                 }
468
469                 internal static object CreateInstanceForAnotherGenericParameter (Type genericType, RuntimeType genericArgument)
470                 {
471                         var gt = (RuntimeType) MakeGenericType (genericType, new Type [] { genericArgument });
472                         var ctor = gt.GetDefaultConstructor ();
473                         return ctor.InternalInvoke (null, null);
474                 }
475
476                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
477                 static extern Type MakeGenericType (Type gt, Type [] types);
478
479                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
480                 internal extern RuntimeMethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type);
481
482                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
483                 extern RuntimePropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, bool icase, Type reflected_type);              
484
485                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
486                 extern RuntimeConstructorInfo[] GetConstructors_internal (BindingFlags bindingAttr, Type reflected_type);
487
488                 public override InterfaceMapping GetInterfaceMap (Type ifaceType)
489                 {
490                         if (IsGenericParameter)
491                                 throw new InvalidOperationException(Environment.GetResourceString("Arg_GenericParameter"));
492                 
493                         if ((object)ifaceType == null)
494                                 throw new ArgumentNullException("ifaceType");
495                         Contract.EndContractBlock();
496
497                         RuntimeType ifaceRtType = ifaceType as RuntimeType;
498
499                         if (ifaceRtType == null)
500                                 throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "ifaceType");
501
502                         InterfaceMapping res;
503                         if (!ifaceType.IsInterface)
504                                 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "ifaceType");
505                         if (IsInterface)
506                                 throw new ArgumentException ("'this' type cannot be an interface itself");
507                         res.TargetType = this;
508                         res.InterfaceType = ifaceType;
509                         GetInterfaceMapData (this, ifaceType, out res.TargetMethods, out res.InterfaceMethods);
510                         if (res.TargetMethods == null)
511                                 throw new ArgumentException (Locale.GetText ("Interface not found"), "ifaceType");
512
513                         return res;
514                 }
515
516                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
517                 static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);                
518
519                 public override Guid GUID {
520                         get {
521                                 object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
522                                 if (att.Length == 0)
523                                         return Guid.Empty;
524                                 return new Guid(((System.Runtime.InteropServices.GuidAttribute)att[0]).Value);
525                         }
526                 }
527
528                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
529                 internal extern void GetPacking (out int packing, out int size);
530
531 #if MONO_COM
532                 private static Dictionary<Guid, Type> clsid_types;
533                 private static AssemblyBuilder clsid_assemblybuilder;
534 #endif
535
536                 internal static Type GetTypeFromCLSIDImpl(Guid clsid, String server, bool throwOnError)
537                 {
538 #if MONO_COM
539                         Type result;
540
541                         if (clsid_types == null)
542                         {
543                                 Dictionary<Guid, Type> new_clsid_types = new Dictionary<Guid, Type> ();
544                                 Interlocked.CompareExchange<Dictionary<Guid, Type>>(
545                                         ref clsid_types, new_clsid_types, null);
546                         }
547
548                         lock (clsid_types) {
549                                 if (clsid_types.TryGetValue(clsid, out result))
550                                         return result;
551
552                                 if (clsid_assemblybuilder == null)
553                                 {
554                                         AssemblyName assemblyname = new AssemblyName ();
555                                         assemblyname.Name = "GetTypeFromCLSIDDummyAssembly";
556                                         clsid_assemblybuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (
557                                                 assemblyname, AssemblyBuilderAccess.Run);
558                                 }
559                                 ModuleBuilder modulebuilder = clsid_assemblybuilder.DefineDynamicModule (
560                                         clsid.ToString ());
561
562                                 TypeBuilder typebuilder = modulebuilder.DefineType ("System.__ComObject",
563                                         TypeAttributes.Public | TypeAttributes.Class, typeof(System.__ComObject));
564
565                                 Type[] guidattrtypes = new Type[] { typeof(string) };
566
567                                 CustomAttributeBuilder customattr = new CustomAttributeBuilder (
568                                         typeof(GuidAttribute).GetConstructor (guidattrtypes),
569                                         new object[] { clsid.ToString () });
570
571                                 typebuilder.SetCustomAttribute (customattr);
572
573                                 customattr = new CustomAttributeBuilder (
574                                         typeof(ComImportAttribute).GetConstructor (EmptyTypes),
575                                         new object[0] {});
576
577                                 typebuilder.SetCustomAttribute (customattr);
578
579                                 result = typebuilder.CreateType ();
580
581                                 clsid_types.Add(clsid, result);
582
583                                 return result;
584                         }
585 #else
586                         throw new NotImplementedException ("Unmanaged activation removed");
587 #endif
588                 }
589
590                 protected override TypeCode GetTypeCodeImpl ()
591                 {
592                         return GetTypeCodeImplInternal (this);
593                 }
594
595                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
596                 extern static TypeCode GetTypeCodeImplInternal (Type type);             
597
598                 internal static Type GetTypeFromProgIDImpl(String progID, String server, bool throwOnError)
599                 {
600                         throw new NotImplementedException ("Unmanaged activation is not supported");
601                 }
602
603                 public override string ToString()
604                 {
605                         return getFullName (false, false);
606                 }
607
608                 bool IsGenericCOMObjectImpl ()
609                 {
610                         return false;
611                 }
612
613                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
614                 static extern object CreateInstanceInternal (Type type);
615
616                 public extern override MethodBase DeclaringMethod {
617                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
618                         get;
619                 }               
620                 
621                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
622                 internal extern string getFullName(bool full_name, bool assembly_qualified);
623
624                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
625                 extern Type[] GetGenericArgumentsInternal (bool runtimeArray);
626
627                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
628                 extern GenericParameterAttributes GetGenericParameterAttributes ();
629
630                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
631                 extern Type[] GetGenericParameterConstraints_impl ();
632
633                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
634                 extern int GetGenericParameterPosition ();
635
636                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
637                 extern RuntimeEventInfo[] GetEvents_internal (string name, BindingFlags bindingAttr, Type reflected_type);
638
639                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
640                 extern RuntimeFieldInfo[] GetFields_internal (string name, BindingFlags bindingAttr, Type reflected_type);
641
642                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
643                 public extern override Type[] GetInterfaces();
644
645                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
646                 extern RuntimeType[] GetNestedTypes_internal (string name, BindingFlags bindingAttr);           
647
648                 public override string AssemblyQualifiedName {
649                         get {
650                                 return getFullName (true, true);
651                         }
652                 }
653
654                 public extern override Type DeclaringType {
655                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
656                         get;
657                 }
658
659                 public extern override string Name {
660                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
661                         get;
662                 }
663
664                 public extern override string Namespace {
665                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
666                         get;
667                 }
668
669 #if MOBILE
670                 static int get_core_clr_security_level ()
671                 {
672                         return 1;
673                 }
674 #else
675                 //seclevel { transparent = 0, safe-critical = 1, critical = 2}
676                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
677                 public extern int get_core_clr_security_level ();
678
679                 public override bool IsSecurityTransparent {
680                         get { return get_core_clr_security_level () == 0; }
681                 }
682
683                 public override bool IsSecurityCritical {
684                         get { return get_core_clr_security_level () > 0; }
685                 }
686
687                 public override bool IsSecuritySafeCritical {
688                         get { return get_core_clr_security_level () == 1; }
689                 }
690 #endif
691
692                 public override int GetHashCode()
693                 {
694                         Type t = UnderlyingSystemType;
695                         if (t != null && t != this)
696                                 return t.GetHashCode ();
697                         return (int)_impl.Value;
698                 }
699
700                 public override string FullName {
701                         get {
702                                 string fullName;
703                                 // This doesn't need locking
704                                 if (type_info == null)
705                                         type_info = new MonoTypeInfo ();
706                                 if ((fullName = type_info.full_name) == null)
707                                         fullName = type_info.full_name = getFullName (true, false);
708
709                                 return fullName;
710                         }
711                 }
712
713                 internal override bool IsUserType {
714                         get {
715                                 return false;
716                         }
717                 }
718         }
719 }