Example #1
0
        /// <summary>
        /// Gets a reference to a primitive kind definition of the appropriate kind.
        /// </summary>
        /// <param name="primitiveType">Primitive type to create a reference for.</param>
        /// <param name="nullable">Flag specifying if the referenced type should be nullable per default.</param>
        /// <returns>A new primitive type reference.</returns>
        private static EdmPrimitiveTypeReference ToTypeReference(IEdmPrimitiveType primitiveType, bool nullable)
        {
            EdmPrimitiveTypeKind kind = primitiveType.PrimitiveKind;

            switch (kind)
            {
            case EdmPrimitiveTypeKind.Boolean:
            case EdmPrimitiveTypeKind.Byte:
            case EdmPrimitiveTypeKind.Double:
            case EdmPrimitiveTypeKind.Guid:
            case EdmPrimitiveTypeKind.Int16:
            case EdmPrimitiveTypeKind.Int32:
            case EdmPrimitiveTypeKind.Int64:
            case EdmPrimitiveTypeKind.SByte:
            case EdmPrimitiveTypeKind.Single:
            case EdmPrimitiveTypeKind.Stream:
                return(new EdmPrimitiveTypeReference(primitiveType, nullable));

            case EdmPrimitiveTypeKind.Binary:
                return(new EdmBinaryTypeReference(primitiveType, nullable));

            case EdmPrimitiveTypeKind.String:
                return(new EdmStringTypeReference(primitiveType, nullable));

            case EdmPrimitiveTypeKind.Decimal:
                return(new EdmDecimalTypeReference(primitiveType, nullable));

            case EdmPrimitiveTypeKind.DateTimeOffset:
            case EdmPrimitiveTypeKind.Duration:
                return(new EdmTemporalTypeReference(primitiveType, nullable));

            case EdmPrimitiveTypeKind.Geography:
            case EdmPrimitiveTypeKind.GeographyPoint:
            case EdmPrimitiveTypeKind.GeographyLineString:
            case EdmPrimitiveTypeKind.GeographyPolygon:
            case EdmPrimitiveTypeKind.GeographyCollection:
            case EdmPrimitiveTypeKind.GeographyMultiPolygon:
            case EdmPrimitiveTypeKind.GeographyMultiLineString:
            case EdmPrimitiveTypeKind.GeographyMultiPoint:
            case EdmPrimitiveTypeKind.Geometry:
            case EdmPrimitiveTypeKind.GeometryPoint:
            case EdmPrimitiveTypeKind.GeometryLineString:
            case EdmPrimitiveTypeKind.GeometryPolygon:
            case EdmPrimitiveTypeKind.GeometryMultiPolygon:
            case EdmPrimitiveTypeKind.GeometryMultiLineString:
            case EdmPrimitiveTypeKind.GeometryMultiPoint:
            case EdmPrimitiveTypeKind.GeometryCollection:
                return(new EdmSpatialTypeReference(primitiveType, nullable));

            default:
                throw new NotSupportedException("Invalid primitive type kind: " + kind.ToString());
            }
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of the IEdmPrimitiveType
 /// </summary>
 /// <param name="primitiveKind">Kind of primitive type.</param>
 /// <returns>Returns a new instance of the IEdmPrimitiveType</returns>
 public static IEdmPrimitiveType CreateType(EdmPrimitiveTypeKind primitiveKind)
 {
     Debug.Assert(primitiveKind != EdmPrimitiveTypeKind.None, "primitiveKiind != EdmPrimitiveTypeKind.None");
     return(new ClientEdmPrimitiveType(XmlConstants.EdmNamespace, primitiveKind.ToString(), primitiveKind));
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmCoreModelPrimitiveType"/> class.
 /// </summary>
 /// <param name="pathKind">The path kind.</param>
 public EdmCoreModelPrimitiveType(EdmPrimitiveTypeKind primitiveKind)
 {
     Name          = primitiveKind.ToString();
     PrimitiveKind = primitiveKind;
 }
Example #4
0
        /// <summary>
        /// Ensures a primitive type reference for a given primitive type kind.
        /// </summary>
        /// <param name="type">The possibly null type reference.</param>
        /// <param name="primitiveKindFromValue">The primitive type kind to ensure.</param>
        /// <returns>An <see cref="IEdmPrimitiveTypeReference"/> instance created for the <paramref name="primitiveKindFromValue"/>
        /// if <paramref name="type"/> is null; if <paramref name="type"/> is not null, validates it and then returns it.</returns>
        private static IEdmPrimitiveTypeReference EnsurePrimitiveType(IEdmPrimitiveTypeReference type, EdmPrimitiveTypeKind primitiveKindFromValue)
        {
            if (type == null)
            {
                type = EdmCoreModel.Instance.GetPrimitive(primitiveKindFromValue, /*isNullable*/ true);
            }
            else
            {
                EdmPrimitiveTypeKind primitiveKindFromType = type.PrimitiveDefinition().PrimitiveKind;

                if (primitiveKindFromType != primitiveKindFromValue)
                {
                    string typeName = type.FullName();
                    if (typeName == null)
                    {
                        throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKindNoTypeName(primitiveKindFromType.ToString(), primitiveKindFromValue.ToString()));
                    }

                    throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKind(typeName, primitiveKindFromValue.ToString(), primitiveKindFromType.ToString()));
                }
            }

            return(type);
        }
        private static IEdmPrimitiveTypeReference ApplyFacetAnnotations(this IEdmPrimitiveTypeReference primitiveTypeReference, List <KeyValuePair <string, object> > annotations)
        {
            object obj2;

            if ((annotations == null) || (annotations.Count == 0))
            {
                return(primitiveTypeReference);
            }
            IEdmPrimitiveTypeReference reference = primitiveTypeReference;
            bool isNullable = primitiveTypeReference.IsNullable;

            if (TryFindAndRemoveAnnotation(annotations, "Nullable", out obj2))
            {
                isNullable = ConvertAnnotationValue <bool>(obj2, "Nullable");
            }
            EdmPrimitiveTypeKind kind = primitiveTypeReference.PrimitiveKind();

            switch (kind)
            {
            case EdmPrimitiveTypeKind.Binary:
                return(CreateBinaryTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.Boolean:
            case EdmPrimitiveTypeKind.Byte:
            case EdmPrimitiveTypeKind.Double:
            case EdmPrimitiveTypeKind.Guid:
            case EdmPrimitiveTypeKind.Int16:
            case EdmPrimitiveTypeKind.Int32:
            case EdmPrimitiveTypeKind.Int64:
            case EdmPrimitiveTypeKind.SByte:
            case EdmPrimitiveTypeKind.Single:
            case EdmPrimitiveTypeKind.Stream:
                if (primitiveTypeReference.IsNullable != isNullable)
                {
                    reference = new EdmPrimitiveTypeReference(primitiveTypeReference.PrimitiveDefinition(), isNullable);
                }
                return(reference);

            case EdmPrimitiveTypeKind.DateTime:
            case EdmPrimitiveTypeKind.DateTimeOffset:
            case EdmPrimitiveTypeKind.Time:
                return(CreateTemporalTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.Decimal:
                return(CreateDecimalTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.String:
                return(CreateStringTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.Geography:
            case EdmPrimitiveTypeKind.GeographyPoint:
            case EdmPrimitiveTypeKind.GeographyLineString:
            case EdmPrimitiveTypeKind.GeographyPolygon:
            case EdmPrimitiveTypeKind.GeographyCollection:
            case EdmPrimitiveTypeKind.GeographyMultiPolygon:
            case EdmPrimitiveTypeKind.GeographyMultiLineString:
            case EdmPrimitiveTypeKind.GeographyMultiPoint:
            case EdmPrimitiveTypeKind.Geometry:
            case EdmPrimitiveTypeKind.GeometryPoint:
            case EdmPrimitiveTypeKind.GeometryLineString:
            case EdmPrimitiveTypeKind.GeometryPolygon:
            case EdmPrimitiveTypeKind.GeometryCollection:
            case EdmPrimitiveTypeKind.GeometryMultiPolygon:
            case EdmPrimitiveTypeKind.GeometryMultiLineString:
            case EdmPrimitiveTypeKind.GeometryMultiPoint:
                return(CreateSpatialTypeReference(primitiveTypeReference, isNullable, annotations));
            }
            throw new InvalidOperationException(System.Data.Services.Strings.MetadataProviderUtils_UnsupportedPrimitiveTypeKind(kind.ToString()));
        }
Example #6
0
 public static IEdmPrimitiveType CreateType(EdmPrimitiveTypeKind primitiveKind)
 {
     return(new PrimitiveType.ClientEdmPrimitiveType("Edm", primitiveKind.ToString(), primitiveKind));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmCoreModelPrimitiveType"/> class.
 /// </summary>
 /// <param name="primitiveKind">The primitive type kind.</param>
 public EdmCoreModelPrimitiveType(EdmPrimitiveTypeKind primitiveKind)
 {
     Name          = primitiveKind.ToString();
     PrimitiveKind = primitiveKind;
     FullName      = this.Namespace + "." + this.Name;
 }
Example #8
0
 /// <summary>
 /// Creates a new instance of the IEdmPrimitiveType
 /// </summary>
 /// <param name="primitiveKind">Kind of primitive type.</param>
 /// <returns>Returns a new instance of the IEdmPrimitiveType</returns>
 public static IEdmPrimitiveType CreateType(EdmPrimitiveTypeKind primitiveKind)
 {
     Debug.Assert(primitiveKind != EdmPrimitiveTypeKind.None, "primitiveKiind != EdmPrimitiveTypeKind.None");
     return new ClientEdmPrimitiveType(XmlConstants.EdmNamespace, primitiveKind.ToString(), primitiveKind);
 }
 private EdmPrimitiveType(EdmPrimitiveTypeKind kind)
 {
     typeKind = kind;
     base.Name = kind.ToString();
 }
Example #10
0
 internal static string GetTypeNameFromPrimitiveTypeKind(EdmPrimitiveTypeKind primitiveTypeKind)
 {
     return primitiveTypeKind.ToString();
 }
Example #11
0
        /// <summary>
        /// Ensures a primitive type reference for a given primitive type kind.
        /// </summary>
        /// <param name="type">The possibly null type reference.</param>
        /// <param name="primitiveKindFromValue">The primitive type kind to ensure.</param>
        /// <returns>An <see cref="IEdmPrimitiveTypeReference"/> instance created for the <paramref name="primitiveKindFromValue"/> 
        /// if <paramref name="type"/> is null; if <paramref name="type"/> is not null, validates it and then returns it.</returns>
        private static IEdmPrimitiveTypeReference EnsurePrimitiveType(IEdmPrimitiveTypeReference type, EdmPrimitiveTypeKind primitiveKindFromValue)
        {
            if (type == null)
            {
                type = EdmCoreModel.Instance.GetPrimitive(primitiveKindFromValue, /*isNullable*/ true);
            }
            else
            {
                EdmPrimitiveTypeKind primitiveKindFromType = type.PrimitiveDefinition().PrimitiveKind;

                if (primitiveKindFromType != primitiveKindFromValue)
                {
                    string typeName = type.FullName();
                    if (typeName == null)
                    {
                        throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKindNoTypeName(primitiveKindFromType.ToString(), primitiveKindFromValue.ToString()));
                    }

                    throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKind(typeName, primitiveKindFromValue.ToString(), primitiveKindFromType.ToString()));
                }
            }

            return type;
        }
Example #12
0
 public static IEdmPrimitiveType CreateType(EdmPrimitiveTypeKind primitiveKind)
 {
     return new PrimitiveType.ClientEdmPrimitiveType("Edm", primitiveKind.ToString(), primitiveKind);
 }