Permalink
Browse files

Implement Type.IsByRefLike for CoreCLR (#13123)

Since this already exists in CoreRT and the
virtual method will get propagated to CoreCLR,
we might as well make it work here before an IsByRefLike
check finds its way into shared code and starts
throwing NotSupportedExceptions on CoreCLR.
  • Loading branch information...
Atsushi Kanamori authored and jkotas committed Jul 31, 2017
1 parent 8f812c1 commit c61525b5883e883621f98d44f479b15d790b0533
@@ -108,6 +108,7 @@ public TypeDelegator(Type delegatingType)
protected override bool IsPointerImpl() => typeImpl.IsPointer;
protected override bool IsValueTypeImpl() => typeImpl.IsValueType;
protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject;
public override bool IsByRefLike => typeImpl.IsByRefLike;
public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType;
public override Type GetElementType() => typeImpl.GetElementType();
protected override bool HasElementTypeImpl() => typeImpl.HasElementType;
@@ -3447,6 +3447,8 @@ protected override bool IsCOMObjectImpl()
return RuntimeTypeHandle.IsComObject(this, false);
}

public sealed override bool IsByRefLike => RuntimeTypeHandle.IsByRefLike(this);

#if FEATURE_COMINTEROP
internal override bool IsWindowsRuntimeObjectImpl()
{
@@ -377,6 +377,9 @@ internal int GetInterfaceMethodImplementationSlot(RuntimeTypeHandle interfaceHan
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static bool IsInterface(RuntimeType type);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static bool IsByRefLike(RuntimeType type);

[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]
@@ -297,6 +297,7 @@ FCFuncStart(gCOMTypeHandleFuncs)
FCFuncElement("IsComObject", RuntimeTypeHandle::IsComObject)
FCFuncElement("IsValueType", RuntimeTypeHandle::IsValueType)
FCFuncElement("IsInterface", RuntimeTypeHandle::IsInterface)
FCFuncElement("IsByRefLike", RuntimeTypeHandle::IsByRefLike)
QCFuncElement("_IsVisible", RuntimeTypeHandle::IsVisible)
QCFuncElement("ConstructName", RuntimeTypeHandle::ConstructName)
FCFuncElement("CanCastTo", RuntimeTypeHandle::CanCastTo)
@@ -970,6 +970,24 @@ FCIMPL1(FC_BOOL_RET, RuntimeTypeHandle::IsInterface, ReflectClassBaseObject *pTy
}
FCIMPLEND;


FCIMPL1(FC_BOOL_RET, RuntimeTypeHandle::IsByRefLike, ReflectClassBaseObject *pTypeUNSAFE)
{
CONTRACTL {
FCALL_CHECK;
}
CONTRACTL_END;

REFLECTCLASSBASEREF refType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pTypeUNSAFE);

_ASSERTE(refType != NULL);

TypeHandle typeHandle = refType->GetType();

FC_RETURN_BOOL(typeHandle.IsByRefLike());
}
FCIMPLEND

BOOL
QCALLTYPE
RuntimeTypeHandle::IsVisible(
@@ -3115,3 +3133,4 @@ void QCALLTYPE RuntimeMethodHandle::GetCallerType(QCall::StackCrawlMarkHandle pS

return;
}

@@ -193,6 +193,7 @@ class RuntimeTypeHandle {
static FCDECL1(ReflectClassBaseObject*, GetDeclaringType, ReflectClassBaseObject* pType);
static FCDECL1(FC_BOOL_RET, IsValueType, ReflectClassBaseObject* pType);
static FCDECL1(FC_BOOL_RET, IsInterface, ReflectClassBaseObject* pType);
static FCDECL1(FC_BOOL_RET, IsByRefLike, ReflectClassBaseObject* pType);

static
BOOL QCALLTYPE IsVisible(EnregisteredTypeHandle pTypeHandle);
@@ -1546,6 +1546,14 @@ BOOL TypeHandle::IsByRef() const

}

BOOL TypeHandle::IsByRefLike() const
{
LIMITED_METHOD_CONTRACT;

return(!IsTypeDesc() && AsMethodTable()->IsByRefLike());

}

BOOL TypeHandle::IsPointer() const
{
LIMITED_METHOD_CONTRACT;
@@ -513,6 +513,9 @@ class TypeHandle
// BYREF
BOOL IsByRef() const;

// BYREFLIKE (does not return TRUE for IsByRef types)
BOOL IsByRefLike() const;

// PTR
BOOL IsPointer() const;

0 comments on commit c61525b

Please sign in to comment.