public static IEdmTypeReference ToEdmTypeReference(this IEdmType edmType, bool isNullable) { Contract.Requires(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 new ArgumentOutOfRangeException(nameof(edmType)); } }
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> /// Constructs type reference for the given IEdmType /// </summary> /// <param name="edmType">IEdmType to obtain reference to</param> /// <param name="isNullable">Whether the type reference is permitted to be null</param> /// <returns>IEdmTypeReference to given IEdmType</returns> public static IEdmTypeReference ToEdmTypeReference(this IEdmType edmType, bool isNullable = true) { 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: // TODO throw new NotSupportedException("Edm type not supported"); } }
internal static IEdmPrimitiveTypeReference GetEdmPrimitiveTypeReferenceOrNull(Type clrType) { var edmPrimitiveTypeOrNull = GetEdmPrimitiveTypeOrNull(clrType); if (edmPrimitiveTypeOrNull == null) { return(null); } return(model.GetPrimitive(edmPrimitiveTypeOrNull.PrimitiveKind, clrType.IsNullable())); }
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); }
public static IEdmPrimitiveTypeReference GetEdmPrimitiveTypeReferenceOrNull(Type clrType) { IEdmPrimitiveType primitiveType = GetEdmPrimitiveTypeOrNull(clrType); return(primitiveType != null?_coreModel.GetPrimitive(primitiveType.PrimitiveKind, IsNullable(clrType)) : null); }
public void CreatingPrimitiveWithInvalidTypeCausesException() { EdmCoreModel coreModel = EdmCoreModel.Instance; this.VerifyThrowsException(typeof(InvalidOperationException), () => coreModel.GetPrimitive(EdmPrimitiveTypeKind.None, false)); }