private static bool TestTypeMatch(this IEdmType expressionType, IEdmType assertedType, EdmLocation location, bool matchExactly, out IEnumerable <EdmError> discoveredErrors) { if (matchExactly) { if (!expressionType.IsEquivalentTo(assertedType)) { discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) }; return(false); } } else { // A bad type matches anything (so as to avoid generating spurious errors). if (expressionType.TypeKind == EdmTypeKind.None || expressionType.IsBad()) { discoveredErrors = Enumerable.Empty <EdmError>(); return(true); } if (expressionType.TypeKind == EdmTypeKind.Primitive && assertedType.TypeKind == EdmTypeKind.Primitive) { IEdmPrimitiveType primitiveExpressionType = expressionType as IEdmPrimitiveType; IEdmPrimitiveType primitiveAssertedType = assertedType as IEdmPrimitiveType; if (!primitiveExpressionType.PrimitiveKind.PromotesTo(primitiveAssertedType.PrimitiveKind)) { discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindCannotPromoteToAssertedType(expressionType.ToTraceString(), assertedType.ToTraceString())) }; return(false); } } else { if (!expressionType.IsOrInheritsFrom(assertedType)) { discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) }; return(false); } } } discoveredErrors = Enumerable.Empty <EdmError>(); return(true); }