public static bool IsCOMObject(Type type) { #if RHTESTCL return(false); #else return(InteropExtensions.AreTypesAssignable(type.TypeHandle, typeof(__ComObject).TypeHandle)); #endif }
public static bool IsCOMObject(Type type) { #if RHTESTCL return(false); #elif CORECLR return(type.GetTypeInfo().IsSubclassOf(typeof(__ComObject))); #else return(InteropExtensions.AreTypesAssignable(type.TypeHandle, typeof(__ComObject).TypeHandle)); #endif }
public static unsafe void DestroyStructure(IntPtr ptr, Type structuretype) { if (ptr == IntPtr.Zero) { throw new ArgumentNullException(nameof(ptr)); } if (structuretype == null) { throw new ArgumentNullException(nameof(structuretype)); } RuntimeTypeHandle structureTypeHandle = structuretype.TypeHandle; if (structureTypeHandle.IsGenericType() || structureTypeHandle.IsGenericTypeDefinition()) { throw new ArgumentException(SR.Argument_NeedNonGenericType, "t"); } if (structureTypeHandle.IsEnum() || structureTypeHandle.IsInterface() || InteropExtensions.AreTypesAssignable(typeof(Delegate).TypeHandle, structureTypeHandle)) { throw new ArgumentException(SR.Format(SR.Argument_MustHaveLayoutOrBeBlittable, structureTypeHandle.LastResortToString)); } if (structureTypeHandle.IsBlittable()) { // ok to call with blittable structure, but no work to do in this case. return; } IntPtr destroyStructureStub = RuntimeAugments.InteropCallbacks.GetDestroyStructureStub(structureTypeHandle, out bool hasInvalidLayout); if (hasInvalidLayout) { throw new ArgumentException(SR.Format(SR.Argument_MustHaveLayoutOrBeBlittable, structureTypeHandle.LastResortToString)); } // DestroyStructureStub == IntPtr.Zero means its fields don't need to be destroied if (destroyStructureStub != IntPtr.Zero) { CalliIntrinsics.Call <int>( destroyStructureStub, (void *)ptr // unsafe (no need to adjust as it is always struct) ); } }
/// <summary> /// Unwrap if this is a managed wrapper /// Typically used in data binding /// For example, you don't want to data bind against a KeyValuePairImpl<K, V> - you want the real /// KeyValuePair<K, V> /// </summary> /// <param name="target">The object you want to unwrap</param> /// <returns>The original object or the unwrapped object</returns> internal static object UnboxManagedWrapperIfBoxed(object target) { // // If the target is boxed by managed code: // 1. BoxedValue // 2. BoxedKeyValuePair // 3. StandardCustomPropertyProviderProxy/EnumerableCustomPropertyProviderProxy/ListCustomPropertyProviderProxy // // we should use its value for data binding // if (InteropExtensions.AreTypesAssignable(target.GetTypeHandle(), typeof(IManagedWrapper).TypeHandle)) { target = ((IManagedWrapper)target).GetTarget(); Debug.Assert(!(target is IManagedWrapper)); } return(target); }
public static unsafe void DestroyStructure(IntPtr ptr, Type structuretype) { if (ptr == IntPtr.Zero) { throw new ArgumentNullException(nameof(ptr)); } if (structuretype == null) { throw new ArgumentNullException(nameof(structuretype)); } RuntimeTypeHandle structureTypeHandle = structuretype.TypeHandle; if (structureTypeHandle.IsGenericType() || structureTypeHandle.IsGenericTypeDefinition()) { throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(structuretype)); } if (structureTypeHandle.IsEnum() || structureTypeHandle.IsInterface() || InteropExtensions.AreTypesAssignable(typeof(Delegate).TypeHandle, structureTypeHandle)) { throw new ArgumentException(SR.Format(SR.Argument_MustHaveLayoutOrBeBlittable, structureTypeHandle.LastResortToString)); } if (structureTypeHandle.IsBlittable()) { // ok to call with blittable structure, but no work to do in this case. return; } IntPtr destroyStructureStub = RuntimeInteropData.GetDestroyStructureStub(structureTypeHandle, out bool hasInvalidLayout); if (hasInvalidLayout) { throw new ArgumentException(SR.Format(SR.Argument_MustHaveLayoutOrBeBlittable, structureTypeHandle.LastResortToString)); } // DestroyStructureStub == IntPtr.Zero means its fields don't need to be destroyed if (destroyStructureStub != IntPtr.Zero) { ((delegate * < ref byte, void >)destroyStructureStub)(ref *(byte *)ptr); } }
public static bool IsDelegate(this RuntimeTypeHandle handle) { return(InteropExtensions.AreTypesAssignable(handle, typeof(MulticastDelegate).TypeHandle) || InteropExtensions.AreTypesAssignable(handle, typeof(Delegate).TypeHandle)); }