__CastResult __CanCastParamNoGC(DmdType fromParam, DmdType toParam) { if (fromParam == toParam) { return(__CastResult.CanCast); } var fromParamCorType = fromParam.__GetVerifierCorElementType(); if (__IsObjRef(fromParamCorType)) { return(fromParam.__CanCastToNoGC(toParam)); } else if (__IsGenericVariable(fromParamCorType)) { if (!fromParam.__ConstrainedAsObjRef()) { return(__CastResult.CannotCast); } return(fromParam.__CanCastToNoGC(toParam)); } else if (__IsPrimitiveType(fromParamCorType)) { var toParamCorType = toParam.__GetVerifierCorElementType(); if (__IsPrimitiveType(toParamCorType)) { if (toParamCorType == fromParamCorType) { return(__CastResult.CanCast); } if ((toParamCorType != DDN.ElementType.Boolean) && (fromParamCorType != DDN.ElementType.Boolean) && (toParamCorType != DDN.ElementType.Char) && (fromParamCorType != DDN.ElementType.Char)) { if ((__Size(toParamCorType) == __Size(fromParamCorType)) && (__IsFloat(toParamCorType) == __IsFloat(fromParamCorType))) { return(__CastResult.CanCast); } } } } else { if (fromParam.HasTypeEquivalence) { return(__CastResult.MaybeCast); } if (toParam.HasTypeEquivalence) { return(__CastResult.MaybeCast); } } return(__CastResult.CannotCast); }
static bool __CanCastTo(DmdType from, DmdType to) { if ((object)from == null) { throw new ArgumentNullException(nameof(from)); } if ((object)to == null) { throw new ArgumentNullException(nameof(to)); } bool res; var r = from.__CanCastToNoGC(to); if (r == __CastResult.MaybeCast) { res = from.__CanCastTo(to); } else { res = r == __CastResult.CanCast; } if (!res && to.IsNullable && !from.__IsTypeDesc()) { if (__IsNullableForType(to, from)) { res = true; } } return(res); }