5 // Marek Safar <marek.safar@gmail.com>
7 // Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
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
;
36 using System
.Reflection
.Emit
;
38 using System
.Diagnostics
.Contracts
;
39 using System
.Security
;
40 using System
.Runtime
.Serialization
;
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 RuntimeConstructorInfo default_ctor
;
54 [StructLayout (LayoutKind
.Sequential
)]
55 partial class RuntimeType
57 #region keep in sync with object-internals.h
59 MonoTypeInfo type_info
;
62 internal Object GenericCache
;
64 internal RuntimeType (Object obj
)
66 throw new NotImplementedException ();
69 internal RuntimeConstructorInfo
GetDefaultConstructor ()
71 RuntimeConstructorInfo ctor
= null;
73 if (type_info
== null)
74 type_info
= new MonoTypeInfo ();
76 ctor
= type_info
.default_ctor
;
79 var ctors
= GetConstructors (BindingFlags
.Public
| BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.DeclaredOnly
);
81 for (int i
= 0; i
< ctors
.Length
; ++i
) {
82 if (ctors
[i
].GetParametersCount () == 0) {
83 type_info
.default_ctor
= ctor
= (RuntimeConstructorInfo
) ctors
[i
];
92 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
93 extern MethodInfo
GetCorrespondingInflatedMethod (MethodInfo generic
);
95 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
96 extern ConstructorInfo
GetCorrespondingInflatedConstructor (ConstructorInfo generic
);
98 internal override MethodInfo
GetMethod (MethodInfo fromNoninstanciated
)
100 if (fromNoninstanciated
== null)
101 throw new ArgumentNullException ("fromNoninstanciated");
102 return GetCorrespondingInflatedMethod (fromNoninstanciated
);
105 internal override ConstructorInfo
GetConstructor (ConstructorInfo fromNoninstanciated
)
107 if (fromNoninstanciated
== null)
108 throw new ArgumentNullException ("fromNoninstanciated");
109 return GetCorrespondingInflatedConstructor (fromNoninstanciated
);
112 internal override FieldInfo
GetField (FieldInfo fromNoninstanciated
)
114 /* create sensible flags from given FieldInfo */
115 BindingFlags flags
= fromNoninstanciated
.IsStatic
? BindingFlags
.Static
: BindingFlags
.Instance
;
116 flags
|= fromNoninstanciated
.IsPublic
? BindingFlags
.Public
: BindingFlags
.NonPublic
;
117 return GetField (fromNoninstanciated
.Name
, flags
);
120 string GetDefaultMemberName ()
122 object [] att
= GetCustomAttributes (typeof (DefaultMemberAttribute
), true);
123 return att
.Length
!= 0 ? ((DefaultMemberAttribute
) att
[0]).MemberName
: null;
126 RuntimeConstructorInfo m_serializationCtor
;
127 internal RuntimeConstructorInfo
GetSerializationCtor()
129 if (m_serializationCtor
== null) {
130 var s_SICtorParamTypes
= new Type
[] { typeof(SerializationInfo), typeof(StreamingContext) }
;
132 m_serializationCtor
= GetConstructor(
133 BindingFlags
.Instance
| BindingFlags
.Public
| BindingFlags
.NonPublic
,
135 CallingConventions
.Any
,
137 null) as RuntimeConstructorInfo
;
140 return m_serializationCtor
;
143 internal Object
CreateInstanceSlow(bool publicOnly
, bool wrapExceptions
, bool skipCheckThis
, bool fillCache
)
145 //bool bNeedSecurityCheck = true;
146 //bool bCanBeCached = false;
147 //bool bSecurityCheckOff = false;
150 CreateInstanceCheckThis();
153 // bSecurityCheckOff = true;
155 return CreateInstanceMono (!publicOnly
, wrapExceptions
);
158 object CreateInstanceMono (bool nonPublic
, bool wrapExceptions
)
160 var ctor
= GetDefaultConstructor ();
161 if (!nonPublic
&& ctor
!= null && !ctor
.IsPublic
) {
166 Type elementType
= this.GetRootElementType();
167 if (ReferenceEquals (elementType
, typeof (TypedReference
)) || ReferenceEquals (elementType
, typeof (RuntimeArgumentHandle
)))
168 throw new NotSupportedException (Environment
.GetResourceString ("NotSupported_ContainsStackPtr"));
171 return CreateInstanceInternal (this);
173 throw new MissingMethodException ("Default constructor not found for type " + FullName
);
176 // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance
178 throw new MissingMethodException ("Cannot create an abstract class '{0}'.", FullName
);
181 return ctor
.InternalInvoke (null, null, wrapExceptions
);
184 internal Object
CheckValue (Object
value, Binder binder
, CultureInfo culture
, BindingFlags invokeAttr
)
187 var res
= TryConvertToType (value, ref failed
);
191 if ((invokeAttr
& BindingFlags
.ExactBinding
) == BindingFlags
.ExactBinding
)
192 throw new ArgumentException(String
.Format(CultureInfo
.CurrentUICulture
, Environment
.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
194 if (binder
!= null && binder
!= Type
.DefaultBinder
)
195 return binder
.ChangeType (value, this, culture
);
197 throw new ArgumentException(String
.Format(CultureInfo
.CurrentUICulture
, Environment
.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
200 object TryConvertToType (object value, ref bool failed
)
202 if (IsInstanceOfType (value)) {
207 var elementType
= GetElementType ();
208 if (value == null || elementType
.IsInstanceOfType (value)) {
217 var type
= Enum
.GetUnderlyingType (this);
218 if (type
== value.GetType ())
220 var res
= IsConvertibleToPrimitiveType (value, this);
223 } else if (IsPrimitive
) {
224 var res
= IsConvertibleToPrimitiveType (value, this);
227 } else if (IsPointer
) {
228 var vtype
= value.GetType ();
229 if (vtype
== typeof (IntPtr
) || vtype
== typeof (UIntPtr
))
237 // Binder uses some incompatible conversion rules. For example
238 // int value cannot be used with decimal parameter but in other
239 // ways it's more flexible than normal convertor, for example
240 // long value can be used with int based enum
241 static object IsConvertibleToPrimitiveType (object value, Type targetType
)
243 var type
= value.GetType ();
245 type
= Enum
.GetUnderlyingType (type
);
246 if (type
== targetType
)
250 var from = Type
.GetTypeCode (type
);
251 var to
= Type
.GetTypeCode (targetType
);
257 return (Char
) (Byte
) value;
258 case TypeCode
.UInt16
:
265 return (Int16
) (Byte
) value;
267 return (Int16
) (SByte
) value;
270 case TypeCode
.UInt16
:
273 return (UInt16
) (Byte
) value;
281 return (Int32
) (Byte
) value;
283 return (Int32
) (SByte
) value;
285 return (Int32
) (Char
) value;
287 return (Int32
) (Int16
) value;
288 case TypeCode
.UInt16
:
289 return (Int32
) (UInt16
) value;
292 case TypeCode
.UInt32
:
295 return (UInt32
) (Byte
) value;
297 return (UInt32
) (Char
) value;
298 case TypeCode
.UInt16
:
299 return (UInt32
) (UInt16
) value;
305 return (Int64
) (Byte
) value;
307 return (Int64
) (SByte
) value;
309 return (Int64
) (Int16
) value;
311 return (Int64
) (Char
) value;
312 case TypeCode
.UInt16
:
313 return (Int64
) (UInt16
) value;
315 return (Int64
) (Int32
) value;
316 case TypeCode
.UInt32
:
317 return (Int64
) (UInt32
) value;
320 case TypeCode
.UInt64
:
323 return (UInt64
) (Byte
) value;
325 return (UInt64
) (Char
) value;
326 case TypeCode
.UInt16
:
327 return (UInt64
) (UInt16
) value;
328 case TypeCode
.UInt32
:
329 return (UInt64
) (UInt32
) value;
332 case TypeCode
.Single
:
335 return (Single
) (Byte
) value;
337 return (Single
) (SByte
) value;
339 return (Single
) (Int16
) value;
341 return (Single
) (Char
) value;
342 case TypeCode
.UInt16
:
343 return (Single
) (UInt16
) value;
345 return (Single
) (Int32
) value;
346 case TypeCode
.UInt32
:
347 return (Single
) (UInt32
) value;
349 return (Single
) (Int64
) value;
350 case TypeCode
.UInt64
:
351 return (Single
) (UInt64
) value;
354 case TypeCode
.Double
:
357 return (Double
) (Byte
) value;
359 return (Double
) (SByte
) value;
361 return (Double
) (Char
) value;
363 return (Double
) (Int16
) value;
364 case TypeCode
.UInt16
:
365 return (Double
) (UInt16
) value;
367 return (Double
) (Int32
) value;
368 case TypeCode
.UInt32
:
369 return (Double
) (UInt32
) value;
371 return (Double
) (Int64
) value;
372 case TypeCode
.UInt64
:
373 return (Double
) (UInt64
) value;
374 case TypeCode
.Single
:
375 return (Double
) (Single
) value;
380 // Everything else is rejected
384 string GetCachedName (TypeNameKind kind
)
387 case TypeNameKind
.SerializationName
:
390 throw new NotImplementedException ();
394 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
395 extern Type
make_array_type (int rank
);
397 public override Type
MakeArrayType ()
399 return make_array_type (0);
402 public override Type
MakeArrayType (int rank
)
404 if (rank
< 1 || rank
> 255)
405 throw new IndexOutOfRangeException ();
406 return make_array_type (rank
);
409 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
410 extern Type
make_byref_type ();
412 public override Type
MakeByRefType ()
415 throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
416 return make_byref_type ();
419 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
420 static extern Type
MakePointerType (Type type
);
422 public override Type
MakePointerType ()
425 throw new TypeLoadException ($"Could not load type '{GetType()}' from assembly '{AssemblyQualifiedName}");
426 return MakePointerType (this);
429 public override StructLayoutAttribute StructLayoutAttribute
{
431 return StructLayoutAttribute
.GetCustomAttribute (this);
435 public override bool ContainsGenericParameters
{
437 if (IsGenericParameter
)
441 foreach (Type arg
in GetGenericArguments ())
442 if (arg
.ContainsGenericParameters
)
447 return GetElementType ().ContainsGenericParameters
;
453 public override Type
[] GetGenericParameterConstraints()
455 if (!IsGenericParameter
)
456 throw new InvalidOperationException(Environment
.GetResourceString("Arg_NotGenericParameter"));
457 Contract
.EndContractBlock();
459 var paramInfo
= new Mono
.RuntimeGenericParamInfoHandle (RuntimeTypeHandle
.GetGenericParameterInfo (this));
460 Type
[] constraints
= paramInfo
.Constraints
;
462 if (constraints
== null)
463 constraints
= EmptyArray
<Type
>.Value
;
468 internal static object CreateInstanceForAnotherGenericParameter (Type genericType
, RuntimeType genericArgument
)
470 var gt
= (RuntimeType
) MakeGenericType (genericType
, new Type
[] { genericArgument }
);
471 var ctor
= gt
.GetDefaultConstructor ();
472 return ctor
.InternalInvoke (null, null, wrapExceptions
: true);
475 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
476 static extern Type
MakeGenericType (Type gt
, Type
[] types
);
478 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
479 internal extern IntPtr
GetMethodsByName_native (IntPtr namePtr
, BindingFlags bindingAttr
, MemberListType listType
);
481 internal RuntimeMethodInfo
[] GetMethodsByName (string name
, BindingFlags bindingAttr
, MemberListType listType
, RuntimeType reflectedType
)
483 var refh
= new RuntimeTypeHandle (reflectedType
);
484 using (var namePtr
= new Mono
.SafeStringMarshal (name
))
485 using (var h
= new Mono
.SafeGPtrArrayHandle (GetMethodsByName_native (namePtr
.Value
, bindingAttr
, listType
))) {
487 var a
= new RuntimeMethodInfo
[n
];
488 for (int i
= 0; i
< n
; i
++) {
489 var mh
= new RuntimeMethodHandle (h
[i
]);
490 a
[i
] = (RuntimeMethodInfo
) RuntimeMethodInfo
.GetMethodFromHandleNoGenericCheck (mh
, refh
);
496 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
497 extern IntPtr
GetPropertiesByName_native (IntPtr name
, BindingFlags bindingAttr
, MemberListType listType
);
499 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
500 extern IntPtr
GetConstructors_native (BindingFlags bindingAttr
);
502 RuntimeConstructorInfo
[] GetConstructors_internal (BindingFlags bindingAttr
, RuntimeType reflectedType
)
504 var refh
= new RuntimeTypeHandle (reflectedType
);
505 using (var h
= new Mono
.SafeGPtrArrayHandle (GetConstructors_native (bindingAttr
))) {
507 var a
= new RuntimeConstructorInfo
[n
];
508 for (int i
= 0; i
< n
; i
++) {
509 var mh
= new RuntimeMethodHandle (h
[i
]);
510 a
[i
] = (RuntimeConstructorInfo
) RuntimeMethodInfo
.GetMethodFromHandleNoGenericCheck (mh
, refh
);
516 RuntimePropertyInfo
[] GetPropertiesByName (string name
, BindingFlags bindingAttr
, MemberListType listType
, RuntimeType reflectedType
)
518 var refh
= new RuntimeTypeHandle (reflectedType
);
519 using (var namePtr
= new Mono
.SafeStringMarshal (name
))
520 using (var h
= new Mono
.SafeGPtrArrayHandle (GetPropertiesByName_native (namePtr
.Value
, bindingAttr
, listType
))) {
522 var a
= new RuntimePropertyInfo
[n
];
523 for (int i
= 0; i
< n
; i
++) {
524 var ph
= new Mono
.RuntimePropertyHandle (h
[i
]);
525 a
[i
] = (RuntimePropertyInfo
) RuntimePropertyInfo
.GetPropertyFromHandle (ph
, refh
);
531 public override InterfaceMapping
GetInterfaceMap (Type ifaceType
)
533 if (IsGenericParameter
)
534 throw new InvalidOperationException(Environment
.GetResourceString("Arg_GenericParameter"));
536 if ((object)ifaceType
== null)
537 throw new ArgumentNullException("ifaceType");
538 Contract
.EndContractBlock();
540 RuntimeType ifaceRtType
= ifaceType
as RuntimeType
;
542 if (ifaceRtType
== null)
543 throw new ArgumentException(Environment
.GetResourceString("Argument_MustBeRuntimeType"), "ifaceType");
545 InterfaceMapping res
;
546 if (!ifaceType
.IsInterface
)
547 throw new ArgumentException ("Argument must be an interface.", "ifaceType");
549 throw new ArgumentException ("'this' type cannot be an interface itself");
550 res
.TargetType
= this;
551 res
.InterfaceType
= ifaceType
;
552 GetInterfaceMapData (this, ifaceType
, out res
.TargetMethods
, out res
.InterfaceMethods
);
553 if (res
.TargetMethods
== null)
554 throw new ArgumentException ("Interface not found", "ifaceType");
559 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
560 static extern void GetInterfaceMapData (Type t
, Type iface
, out MethodInfo
[] targets
, out MethodInfo
[] methods
);
562 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
563 private extern static void GetGUID (Type type
, byte[] guid
);
565 public override Guid GUID
{
567 var guid
= new byte [16];
568 GetGUID (this, guid
);
569 return new Guid (guid
);
573 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
574 internal extern void GetPacking (out int packing
, out int size
);
577 private static Dictionary
<Guid
, Type
> clsid_types
;
578 private static AssemblyBuilder clsid_assemblybuilder
;
581 internal static Type
GetTypeFromCLSIDImpl(Guid clsid
, String server
, bool throwOnError
)
586 if (clsid_types
== null)
588 Dictionary
<Guid
, Type
> new_clsid_types
= new Dictionary
<Guid
, Type
> ();
589 Interlocked
.CompareExchange
<Dictionary
<Guid
, Type
>>(
590 ref clsid_types
, new_clsid_types
, null);
594 if (clsid_types
.TryGetValue(clsid
, out result
))
597 if (clsid_assemblybuilder
== null)
599 AssemblyName assemblyname
= new AssemblyName ();
600 assemblyname
.Name
= "GetTypeFromCLSIDDummyAssembly";
601 /* Dynamically created assembly is marked internal to corlib to allow
602 __ComObject access for dynamic types. */
603 clsid_assemblybuilder
= new AssemblyBuilder (assemblyname
, null,
604 AssemblyBuilderAccess
.Run
, true);
606 ModuleBuilder modulebuilder
= clsid_assemblybuilder
.DefineDynamicModule (
609 TypeBuilder typebuilder
= modulebuilder
.DefineType ("System.__ComObject",
610 TypeAttributes
.Public
| TypeAttributes
.Class
, typeof(System
.__ComObject
));
612 Type
[] guidattrtypes
= new Type
[] { typeof(string) }
;
614 CustomAttributeBuilder customattr
= new CustomAttributeBuilder (
615 typeof(GuidAttribute
).GetConstructor (guidattrtypes
),
616 new object[] { clsid.ToString () }
);
618 typebuilder
.SetCustomAttribute (customattr
);
620 customattr
= new CustomAttributeBuilder (
621 typeof(ComImportAttribute
).GetConstructor (EmptyTypes
),
624 typebuilder
.SetCustomAttribute (customattr
);
626 result
= typebuilder
.CreateType ();
628 clsid_types
.Add(clsid
, result
);
633 throw new NotImplementedException ("Unmanaged activation removed");
637 protected override TypeCode
GetTypeCodeImpl ()
639 return GetTypeCodeImplInternal (this);
642 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
643 extern static TypeCode
GetTypeCodeImplInternal (Type type
);
645 internal static Type
GetTypeFromProgIDImpl(String progID
, String server
, bool throwOnError
)
647 throw new NotImplementedException ("Unmanaged activation is not supported");
650 public override string ToString()
652 return getFullName (false, false);
655 bool IsGenericCOMObjectImpl ()
660 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
661 static extern object CreateInstanceInternal (Type type
);
663 public extern override MethodBase DeclaringMethod
{
664 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
668 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
669 internal extern string getFullName(bool full_name
, bool assembly_qualified
);
671 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
672 extern Type
[] GetGenericArgumentsInternal (bool runtimeArray
);
674 GenericParameterAttributes
GetGenericParameterAttributes () {
675 return (new Mono
.RuntimeGenericParamInfoHandle (RuntimeTypeHandle
.GetGenericParameterInfo (this))).Attributes
;
678 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
679 extern int GetGenericParameterPosition ();
681 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
682 extern IntPtr
GetEvents_native (IntPtr name
, MemberListType listType
);
684 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
685 extern IntPtr
GetFields_native (IntPtr name
, BindingFlags bindingAttr
, MemberListType listType
);
687 RuntimeFieldInfo
[] GetFields_internal (string name
, BindingFlags bindingAttr
, MemberListType listType
, RuntimeType reflectedType
)
689 var refh
= new RuntimeTypeHandle (reflectedType
);
690 using (var namePtr
= new Mono
.SafeStringMarshal (name
))
691 using (var h
= new Mono
.SafeGPtrArrayHandle (GetFields_native (namePtr
.Value
, bindingAttr
, listType
))) {
693 var a
= new RuntimeFieldInfo
[n
];
694 for (int i
= 0; i
< n
; i
++) {
695 var fh
= new RuntimeFieldHandle (h
[i
]);
696 a
[i
] = (RuntimeFieldInfo
) FieldInfo
.GetFieldFromHandle (fh
, refh
);
702 RuntimeEventInfo
[] GetEvents_internal (string name
, BindingFlags bindingAttr
, MemberListType listType
, RuntimeType reflectedType
)
704 var refh
= new RuntimeTypeHandle (reflectedType
);
705 using (var namePtr
= new Mono
.SafeStringMarshal (name
))
706 using (var h
= new Mono
.SafeGPtrArrayHandle (GetEvents_native (namePtr
.Value
, listType
))) {
708 var a
= new RuntimeEventInfo
[n
];
709 for (int i
= 0; i
< n
; i
++) {
710 var eh
= new Mono
.RuntimeEventHandle (h
[i
]);
711 a
[i
] = (RuntimeEventInfo
) EventInfo
.GetEventFromHandle (eh
, refh
);
717 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
718 public extern override Type
[] GetInterfaces();
720 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
721 extern IntPtr
GetNestedTypes_native (IntPtr name
, BindingFlags bindingAttr
, MemberListType listType
);
723 RuntimeType
[] GetNestedTypes_internal (string displayName
, BindingFlags bindingAttr
, MemberListType listType
)
725 string internalName
= null;
726 if (displayName
!= null)
727 internalName
= TypeIdentifiers
.FromDisplay (displayName
).InternalName
;
728 using (var namePtr
= new Mono
.SafeStringMarshal (internalName
))
729 using (var h
= new Mono
.SafeGPtrArrayHandle (GetNestedTypes_native (namePtr
.Value
, bindingAttr
, listType
))) {
731 var a
= new RuntimeType
[n
];
732 for (int i
= 0; i
< n
; i
++) {
733 var th
= new RuntimeTypeHandle (h
[i
]);
734 a
[i
] = (RuntimeType
) Type
.GetTypeFromHandle (th
);
740 public override string AssemblyQualifiedName
{
742 return getFullName (true, true);
746 public extern override Type DeclaringType
{
747 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
751 public extern override string Name
{
752 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
756 public extern override string Namespace
{
757 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
762 static int get_core_clr_security_level ()
767 //seclevel { transparent = 0, safe-critical = 1, critical = 2}
768 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
769 public extern int get_core_clr_security_level ();
771 public override bool IsSecurityTransparent
{
772 get { return get_core_clr_security_level () == 0; }
775 public override bool IsSecurityCritical
{
776 get { return get_core_clr_security_level () > 0; }
779 public override bool IsSecuritySafeCritical
{
780 get { return get_core_clr_security_level () == 1; }
784 public override int GetHashCode()
786 Type t
= UnderlyingSystemType
;
787 if (t
!= null && t
!= this)
788 return t
.GetHashCode ();
789 return (int)_impl
.Value
;
792 public override string FullName
{
794 // See https://github.com/mono/mono/issues/18180 and
795 // https://github.com/dotnet/runtime/blob/f23e2796ab5f6fea71c9fdacac024822280253db/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs#L1468-L1472
796 if (ContainsGenericParameters
&& !GetRootElementType().IsGenericTypeDefinition
)
800 // This doesn't need locking
801 if (type_info
== null)
802 type_info
= new MonoTypeInfo ();
803 if ((fullName
= type_info
.full_name
) == null)
804 fullName
= type_info
.full_name
= getFullName (true, false);
810 public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other
) => HasSameMetadataDefinitionAsCore
<RuntimeType
> (other
);
812 public override bool IsSZArray
{
815 return IsArray
&& ReferenceEquals (this, GetElementType ().MakeArrayType ());
819 internal override bool IsUserType
{
825 [System
.Runtime
.InteropServices
.ComVisible(true)]
827 public override bool IsSubclassOf(Type type
)
829 if ((object)type
== null)
830 throw new ArgumentNullException("type");
831 Contract
.EndContractBlock();
832 RuntimeType rtType
= type
as RuntimeType
;
836 return RuntimeTypeHandle
.IsSubclassOf (this, rtType
);
839 public override bool IsByRefLike
{
841 return RuntimeTypeHandle
.IsByRefLike (this);
845 public override bool IsTypeDefinition
=> RuntimeTypeHandle
.IsTypeDefinition (this);