private static IEdmTypeReference GetTypeReference(IEdmType edmType) { Ensure.NotNull(edmType, nameof(edmType)); var isNullable = false; switch (edmType.TypeKind) { case EdmTypeKind.Collection: return(new EdmCollectionTypeReference(edmType as IEdmCollectionType)); case EdmTypeKind.Complex: return(new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable)); case EdmTypeKind.Entity: return(new EdmEntityTypeReference(edmType as IEdmEntityType, isNullable)); case EdmTypeKind.EntityReference: return(new EdmEntityReferenceTypeReference(edmType as IEdmEntityReferenceType, isNullable)); case EdmTypeKind.Enum: return(new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable)); case EdmTypeKind.Primitive: return(new EdmPrimitiveTypeReference(edmType as IEdmPrimitiveType, isNullable)); default: throw Error.NotSupported(Resources.EdmTypeNotSupported, edmType.ToTraceString()); } }
public static IEdmTypeReference ToEdmTypeReference(this IEdmType edmType, bool isNullable) { Contract.Assert(edmType != null); switch (edmType.TypeKind) { case EdmTypeKind.Collection: return(new EdmCollectionTypeReference(edmType as IEdmCollectionType)); case EdmTypeKind.Complex: return(new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable)); case EdmTypeKind.Entity: return(new EdmEntityTypeReference(edmType as IEdmEntityType, isNullable)); case EdmTypeKind.EntityReference: return(new EdmEntityReferenceTypeReference(edmType as IEdmEntityReferenceType, isNullable)); case EdmTypeKind.Enum: return(new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable)); case EdmTypeKind.Primitive: return(_coreModel.GetPrimitive((edmType as IEdmPrimitiveType).PrimitiveKind, isNullable)); default: throw Error.NotSupported(SRResources.EdmTypeNotSupported, edmType.ToTraceString()); } }
/// <summary> /// Get the type reference based on Edm type /// </summary> /// <param name="edmType">The edm type to retrieve Edm type reference</param> /// <returns>The edm type reference</returns> public static IEdmTypeReference GetTypeReference(this IEdmType edmType) { Ensure.NotNull(edmType, "edmType"); var isNullable = false; switch (edmType.TypeKind) { case EdmTypeKind.Collection: return(new EdmCollectionTypeReference(edmType as IEdmCollectionType)); case EdmTypeKind.Complex: return(new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable)); case EdmTypeKind.Entity: return(new EdmEntityTypeReference(edmType as IEdmEntityType, isNullable)); case EdmTypeKind.EntityReference: return(new EdmEntityReferenceTypeReference(edmType as IEdmEntityReferenceType, isNullable)); case EdmTypeKind.Enum: return(new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable)); case EdmTypeKind.Primitive: return(new EdmPrimitiveTypeReference(edmType as IEdmPrimitiveType, isNullable)); default: string message = string.Format( CultureInfo.CurrentCulture, Resources.EdmTypeNotSupported, edmType.ToTraceString()); throw new NotSupportedException(message); } }
/// <summary> /// Gets the EDM type reference for the EDM type definition. /// </summary> /// <param name="edmType">The EDM type definition.</param> /// <param name="isNullable">Indicates whether the type is nullable.</param> /// <returns>The created EDM type reference.</returns> public static IEdmTypeReference GetEdmTypeReference(this IEdmType edmType, bool isNullable) { Ensure.NotNull(edmType, "edmType"); switch (edmType.TypeKind) { case EdmTypeKind.Collection: return(new EdmCollectionTypeReference(edmType as IEdmCollectionType)); case EdmTypeKind.Complex: return(new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable)); case EdmTypeKind.Entity: return(new EdmEntityTypeReference(edmType as IEdmEntityType, isNullable)); case EdmTypeKind.EntityReference: return(new EdmEntityReferenceTypeReference(edmType as IEdmEntityReferenceType, isNullable)); case EdmTypeKind.Enum: return(new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable)); case EdmTypeKind.Primitive: return(new EdmPrimitiveTypeReference(edmType as IEdmPrimitiveType, isNullable)); default: throw Error.NotSupported(Resources.EdmTypeNotSupported, edmType.ToTraceString()); } }
public static IEdmTypeReference GetEdmTypeReference(this IEdmModel edmModel, Type clrType) { IEdmType edmType = edmModel.GetEdmType(clrType); if (edmType != null) { bool isNullable = IsNullable(clrType); switch (edmType.TypeKind) { case EdmTypeKind.Collection: return(new EdmCollectionTypeReference(edmType as IEdmCollectionType, isNullable)); case EdmTypeKind.Complex: return(new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable)); case EdmTypeKind.Entity: return(new EdmEntityTypeReference(edmType as IEdmEntityType, isNullable)); case EdmTypeKind.EntityReference: return(new EdmEntityReferenceTypeReference(edmType as IEdmEntityReferenceType, isNullable)); case EdmTypeKind.Enum: return(new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable)); case EdmTypeKind.Primitive: return(_coreModel.GetPrimitive((edmType as IEdmPrimitiveType).PrimitiveKind, isNullable)); case EdmTypeKind.Row: return(new EdmRowTypeReference(edmType as IEdmRowType, isNullable)); default: throw Error.NotSupported(SRResources.EdmTypeNotSupported, edmType.ToTraceString()); } } return(null); }
/// <summary> /// Converts an Edm Type to Edm type reference. /// </summary> /// <param name="edmType">The Edm type.</param> /// <param name="isNullable">Nullable value.</param> /// <returns>The Edm type reference.</returns> public static IEdmTypeReference ToEdmTypeReference(this IEdmType edmType, bool isNullable) { if (edmType == null) { throw Error.ArgumentNull(nameof(edmType)); } switch (edmType.TypeKind) { case EdmTypeKind.Collection: return(new EdmCollectionTypeReference((IEdmCollectionType)edmType)); case EdmTypeKind.Complex: return(new EdmComplexTypeReference((IEdmComplexType)edmType, isNullable)); case EdmTypeKind.Entity: return(new EdmEntityTypeReference((IEdmEntityType)edmType, isNullable)); case EdmTypeKind.EntityReference: return(new EdmEntityReferenceTypeReference((IEdmEntityReferenceType)edmType, isNullable)); case EdmTypeKind.Enum: return(new EdmEnumTypeReference((IEdmEnumType)edmType, isNullable)); case EdmTypeKind.Primitive: return(EdmCoreModel.Instance.GetPrimitive(((IEdmPrimitiveType)edmType).PrimitiveKind, isNullable)); case EdmTypeKind.Path: return(new EdmPathTypeReference((IEdmPathType)edmType, isNullable)); case EdmTypeKind.TypeDefinition: return(new EdmTypeDefinitionReference((IEdmTypeDefinition)edmType, isNullable)); default: throw Error.NotSupported(SRResources.EdmTypeNotSupported, edmType.ToTraceString()); } }
private static IEdmTypeReference GetTypeReference(IEdmType edmType) { Ensure.NotNull(edmType, "edmType"); var isNullable = false; switch (edmType.TypeKind) { case EdmTypeKind.Collection: return new EdmCollectionTypeReference(edmType as IEdmCollectionType); case EdmTypeKind.Complex: return new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable); case EdmTypeKind.Entity: return new EdmEntityTypeReference(edmType as IEdmEntityType, isNullable); case EdmTypeKind.EntityReference: return new EdmEntityReferenceTypeReference(edmType as IEdmEntityReferenceType, isNullable); case EdmTypeKind.Enum: return new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable); case EdmTypeKind.Primitive: return new EdmPrimitiveTypeReference(edmType as IEdmPrimitiveType, isNullable); default: throw Error.NotSupported(Resources.EdmTypeNotSupported, edmType.ToTraceString()); } }
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; }
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); }