Example #1
0
        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));
            }
        }
Example #2
0
        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());
            }
        }
Example #3
0
        /// <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");
            }
        }
Example #4
0
        internal static IEdmPrimitiveTypeReference GetEdmPrimitiveTypeReferenceOrNull(Type clrType)
        {
            var edmPrimitiveTypeOrNull = GetEdmPrimitiveTypeOrNull(clrType);

            if (edmPrimitiveTypeOrNull == null)
            {
                return(null);
            }

            return(model.GetPrimitive(edmPrimitiveTypeOrNull.PrimitiveKind, clrType.IsNullable()));
        }
Example #5
0
        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);
        }
Example #6
0
        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));
        }