예제 #1
0
        private static bool CanCastToInternal(this TypeDesc thisType, TypeDesc otherType, StackOverflowProtect protect)
        {
            if (thisType == otherType)
            {
                return(true);
            }

            switch (thisType.Category)
            {
            case TypeFlags.GenericParameter:
                return(((GenericParameterDesc)thisType).CanCastGenericParameterTo(otherType, protect));

            case TypeFlags.Array:
            case TypeFlags.SzArray:
                return(((ArrayType)thisType).CanCastArrayTo(otherType, protect));

            case TypeFlags.ByRef:
            case TypeFlags.Pointer:
                if (otherType.Category == thisType.Category)
                {
                    return(((ParameterizedType)thisType).CanCastParamTo(((ParameterizedType)otherType).ParameterType, protect));
                }
                return(false);

            case TypeFlags.FunctionPointer:
                return(false);

            default:
                Debug.Assert(thisType.IsDefType);
                return(thisType.CanCastToClassOrInterface(otherType, protect));
            }
        }