コード例 #1
0
ファイル: DmdType.CanCastTo.cs プロジェクト: xi4oyu/dnSpy
        bool __ArraySupportsBizarreInterface(DmdType arrayType, DmdType @interface)
        {
            if (arrayType.__GetInternalCorElementType() != DDN.ElementType.SZArray)
            {
                return(false);
            }

            if (!__IsImplicitInterfaceOfSZArray(@interface))
            {
                return(false);
            }

            return(__CanCastParam(arrayType.GetElementType(), @interface.GetGenericArguments()[0]));
        }
コード例 #2
0
ファイル: DmdType.CanCastTo.cs プロジェクト: xi4oyu/dnSpy
        __CastResult __TypeDesc_CanCastToNoGC(DmdType toType)
        {
            Debug.Assert(this != toType);

            if (IsGenericParameter)
            {
                if (toType == AppDomain.System_Object)
                {
                    return(__CastResult.CanCast);
                }

                if (toType == AppDomain.System_ValueType)
                {
                    return(__CastResult.MaybeCast);
                }

                foreach (var constraint in GetGenericParameterConstraints())
                {
                    if (constraint.__CanCastToNoGC(toType) == __CastResult.CanCast)
                    {
                        return(__CastResult.CanCast);
                    }
                }
                return(__CastResult.MaybeCast);
            }

            if (!toType.__IsTypeDesc())
            {
                if (!IsArray)
                {
                    return(__CastResult.CannotCast);
                }
                return(__CanCastToClassOrInterfaceNoGC(toType));
            }

            var toKind   = toType.__GetInternalCorElementType();
            var fromKind = __GetInternalCorElementType();

            if (!(toKind == fromKind || (toKind == DDN.ElementType.Array && fromKind == DDN.ElementType.SZArray)))
            {
                return(__CastResult.CannotCast);
            }

            switch (toKind)
            {
            case DDN.ElementType.Array:
                if (GetArrayRank() != toType.GetArrayRank())
                {
                    return(__CastResult.CannotCast);
                }
                goto case DDN.ElementType.SZArray;

            case DDN.ElementType.SZArray:
            case DDN.ElementType.ByRef:
            case DDN.ElementType.Ptr:
                return(__CanCastParamNoGC(GetElementType(), toType.GetElementType()));

            case DDN.ElementType.Var:
            case DDN.ElementType.MVar:
            case DDN.ElementType.FnPtr:
                return(__CastResult.CannotCast);

            default:
                return(__CastResult.CanCast);
            }
        }
コード例 #3
0
ファイル: DmdType.CanCastTo.cs プロジェクト: xi4oyu/dnSpy
        bool __TypeDesc_CanCastTo(DmdType toType)
        {
            if (this == toType)
            {
                return(true);
            }

            if (IsGenericParameter)
            {
                if (toType == AppDomain.System_Object)
                {
                    return(true);
                }

                if (toType == AppDomain.System_ValueType)
                {
                    if ((GenericParameterAttributes & DmdGenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
                    {
                        return(true);
                    }
                }

                foreach (var constraint in GetGenericParameterConstraints())
                {
                    if (constraint.__CanCastTo(toType))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            if (!toType.__IsTypeDesc())
            {
                if (!IsArray)
                {
                    return(false);
                }

                if (__CanCastToClassOrInterface(toType))
                {
                    return(true);
                }

                if (toType.IsInterface)
                {
                    if (__ArraySupportsBizarreInterface(this, toType))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            var toKind   = toType.__GetInternalCorElementType();
            var fromKind = __GetInternalCorElementType();

            if (!(toKind == fromKind || (toKind == DDN.ElementType.Array && fromKind == DDN.ElementType.SZArray)))
            {
                return(false);
            }

            switch (toKind)
            {
            case DDN.ElementType.Array:
                if (GetArrayRank() != toType.GetArrayRank())
                {
                    return(false);
                }
                goto case DDN.ElementType.SZArray;

            case DDN.ElementType.SZArray:
            case DDN.ElementType.ByRef:
            case DDN.ElementType.Ptr:
                return(__CanCastParam(GetElementType(), toType.GetElementType()));

            case DDN.ElementType.Var:
            case DDN.ElementType.MVar:
            case DDN.ElementType.FnPtr:
                return(false);

            default:
                return(true);
            }
        }