internal override void WriteTemporalTypeAttributes(IEdmTemporalTypeReference reference)
 {
     if (reference.Precision != null)
     {
         this.WriteOptionalAttribute(CsdlConstants.Attribute_Precision, reference.Precision, CsdlConstants.Default_TemporalPrecision, EdmValueWriter.IntAsXml);
     }
 }
Example #2
0
        public void CanConfig_PrecisionOfTemporalType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var entity = builder.EntityType <PrecisionEnitity>().HasKey(p => p.Id);

            entity.Property(p => p.DurationProperty).Precision       = 5;
            entity.Property(p => p.TimeOfDayProperty).Precision      = 6;
            entity.Property(p => p.DateTimeOffsetProperty).Precision = 7;

            // Act
            IEdmModel                 model         = builder.GetEdmModel();
            IEdmEntityType            edmEntityType = model.SchemaElements.OfType <IEdmEntityType>().First(p => p.Name == "PrecisionEnitity");
            IEdmTemporalTypeReference durationType  =
                (IEdmTemporalTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("DurationProperty")).Type;
            IEdmTemporalTypeReference timeOfDayType =
                (IEdmTemporalTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("TimeOfDayProperty")).Type;
            IEdmTemporalTypeReference dateTimeOffsetType =
                (IEdmTemporalTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("DateTimeOffsetProperty")).Type;

            // Assert
            Assert.Equal(5, durationType.Precision.Value);
            Assert.Equal(6, timeOfDayType.Precision.Value);
            Assert.Equal(7, dateTimeOffsetType.Precision.Value);
        }
 private static void AppendTemporalFacets(this StringBuilder sb, IEdmTemporalTypeReference type)
 {
     if (type.Precision != null)
     {
         sb.AppendKeyValue(EdmConstants.FacetName_Precision, type.Precision.ToString());
     }
 }
Example #4
0
        public void ConstructableTypeReferenceToStringTest()
        {
            IEdmEntityType  astonishing  = new EdmEntityType("AwesomeNamespace", "AstonishingEntity", null, false, false);
            IEdmComplexType breathTaking = new EdmComplexType("AwesomeNamespace", "BreathtakingComplex", null, false);

            IEdmEntityTypeReference          entity      = new EdmEntityTypeReference(astonishing, true);
            IEdmComplexTypeReference         complex     = new EdmComplexTypeReference(breathTaking, true);
            IEdmPrimitiveTypeReference       primitive   = EdmCoreModel.Instance.GetInt32(true);
            IEdmStringTypeReference          stringType  = EdmCoreModel.Instance.GetString(false, 128, false, true);
            IEdmBinaryTypeReference          binary      = EdmCoreModel.Instance.GetBinary(true, null, true);
            IEdmTemporalTypeReference        temporal    = EdmCoreModel.Instance.GetTemporal(EdmPrimitiveTypeKind.DateTimeOffset, 1, true);
            IEdmDecimalTypeReference         decimalType = EdmCoreModel.Instance.GetDecimal(3, 2, true);
            IEdmSpatialTypeReference         spatial     = EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, 1, true);
            IEdmEntityReferenceTypeReference entityRef   = new EdmEntityReferenceTypeReference(new EdmEntityReferenceType(astonishing), true);
            IEdmCollectionTypeReference      collection  = EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(true));
            IEdmTypeReference type = new EdmEntityTypeReference(astonishing, true);

            Assert.AreEqual("[AwesomeNamespace.AstonishingEntity Nullable=True]", entity.ToString(), "To string correct");
            Assert.AreEqual("[AwesomeNamespace.BreathtakingComplex Nullable=True]", complex.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Int32 Nullable=True]", primitive.ToString(), "To string correct");
            Assert.AreEqual("[Edm.String Nullable=True MaxLength=128 Unicode=False]", stringType.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Binary Nullable=True MaxLength=max]", binary.ToString(), "To string correct");
            Assert.AreEqual("[Edm.DateTimeOffset Nullable=True Precision=1]", temporal.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Decimal Nullable=True Precision=3 Scale=2]", decimalType.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Geography Nullable=True SRID=1]", spatial.ToString(), "To string correct");
            Assert.AreEqual("[Collection([Edm.Int32 Nullable=True]) Nullable=True]", collection.ToString(), "To string correct");
            Assert.AreEqual("[EntityReference(AwesomeNamespace.AstonishingEntity) Nullable=True]", entityRef.ToString(), "To string correct");
            Assert.AreEqual("[AwesomeNamespace.AstonishingEntity Nullable=True]", type.ToString(), "To string correct");
        }
 private static bool IsEquivalentTo(this IEdmTemporalTypeReference thisType, IEdmTemporalTypeReference otherType)
 {
     return(thisType != null && otherType != null &&
            thisType.TypeKind() == otherType.TypeKind() &&
            thisType.IsNullable == otherType.IsNullable &&
            thisType.Precision == otherType.Precision);
 }
Example #6
0
        /// <summary>
        /// Converts a primitive OData value to the corresponding <see cref="IEdmDelayedValue"/>.
        /// </summary>
        /// <param name="primitiveValue">The primitive OData value to convert.</param>
        /// <param name="type">The <see cref="IEdmTypeReference"/> for the primitive value (if available).</param>
        /// <returns>An <see cref="IEdmDelayedValue"/> for the <paramref name="primitiveValue"/>.</returns>
        internal static IEdmDelayedValue ConvertPrimitiveValue(object primitiveValue, IEdmPrimitiveTypeReference type)
        {
#if !ASTORIA_CLIENT
            DebugUtils.CheckNoExternalCallers();
#endif
            Debug.Assert(primitiveValue != null, "primitiveValue != null");

            TypeCode typeCode = PlatformHelpers.GetTypeCode(primitiveValue.GetType());
            switch (typeCode)
            {
            case TypeCode.Boolean:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Boolean);
                return(new EdmBooleanConstant(type, (bool)primitiveValue));

            case TypeCode.Byte:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Byte);
                return(new EdmIntegerConstant(type, (byte)primitiveValue));

            case TypeCode.SByte:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.SByte);
                return(new EdmIntegerConstant(type, (sbyte)primitiveValue));

            case TypeCode.Int16:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Int16);
                return(new EdmIntegerConstant(type, (Int16)primitiveValue));

            case TypeCode.Int32:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Int32);
                return(new EdmIntegerConstant(type, (Int32)primitiveValue));

            case TypeCode.Int64:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Int64);
                return(new EdmIntegerConstant(type, (Int64)primitiveValue));

            case TypeCode.DateTime:
                IEdmTemporalTypeReference dateTimeType = (IEdmTemporalTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.DateTime);
                return(new EdmDateTimeConstant(dateTimeType, (DateTime)primitiveValue));

            case TypeCode.Decimal:
                IEdmDecimalTypeReference decimalType = (IEdmDecimalTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Decimal);
                return(new EdmDecimalConstant(decimalType, (decimal)primitiveValue));

            case TypeCode.Single:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Single);
                return(new EdmFloatingConstant(type, (Single)primitiveValue));

            case TypeCode.Double:
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Double);
                return(new EdmFloatingConstant(type, (double)primitiveValue));

            case TypeCode.String:
                IEdmStringTypeReference stringType = (IEdmStringTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.String);
                return(new EdmStringConstant(stringType, (string)primitiveValue));

            default:
                return(ConvertPrimitiveValueWithoutTypeCode(primitiveValue, type));
            }
        }
        private static void AppendTemporalFacets(this StringBuilder sb, IEdmTemporalTypeReference type)
        {
            int?precision = type.Precision;

            if (precision.HasValue)
            {
                int?nullable = type.Precision;
                sb.AppendKeyValue("Precision", nullable.ToString());
            }
        }
Example #8
0
        /// <summary>
        /// Convert a primitive value which didn't match any of the known values of the TypeCode enumeration.
        /// </summary>
        /// <param name="primitiveValue">The value to convert.</param>
        /// <param name="type">The expected primitive type or null.</param>
        /// <returns>The converted value.</returns>
        private static IEdmDelayedValue ConvertPrimitiveValueWithoutTypeCode(object primitiveValue, IEdmPrimitiveTypeReference type)
        {
            byte[] bytes = primitiveValue as byte[];
            if (bytes != null)
            {
                IEdmBinaryTypeReference binaryType = (IEdmBinaryTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Binary);
                return(new EdmBinaryConstant(binaryType, bytes));
            }

            if (primitiveValue is Date)
            {
                IEdmPrimitiveTypeReference dateType = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Date);
                return(new EdmDateConstant(dateType, (Date)primitiveValue));
            }

            if (primitiveValue is DateTimeOffset)
            {
                IEdmTemporalTypeReference dateTimeOffsetType = (IEdmTemporalTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.DateTimeOffset);
                return(new EdmDateTimeOffsetConstant(dateTimeOffsetType, (DateTimeOffset)primitiveValue));
            }

            if (primitiveValue is Guid)
            {
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Guid);
                return(new EdmGuidConstant(type, (Guid)primitiveValue));
            }

            if (primitiveValue is TimeOfDay)
            {
                IEdmTemporalTypeReference timeOfDayType = (IEdmTemporalTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.TimeOfDay);
                return(new EdmTimeOfDayConstant(timeOfDayType, (TimeOfDay)primitiveValue));
            }

            if (primitiveValue is TimeSpan)
            {
                IEdmTemporalTypeReference timeType = (IEdmTemporalTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Duration);
                return(new EdmDurationConstant(timeType, (TimeSpan)primitiveValue));
            }

            if (primitiveValue is ISpatial)
            {
                // TODO: [JsonLight] Add support for spatial values in ODataEdmStructuredValue
                throw new NotImplementedException();
            }

#if ASTORIA_CLIENT
            IEdmDelayedValue convertPrimitiveValueWithoutTypeCode;
            if (TryConvertClientSpecificPrimitiveValue(primitiveValue, type, out convertPrimitiveValueWithoutTypeCode))
            {
                return(convertPrimitiveValueWithoutTypeCode);
            }
#endif

            throw new ODataException(ErrorStrings.EdmValueUtils_UnsupportedPrimitiveType(primitiveValue.GetType().FullName));
        }
Example #9
0
        /// <summary>
        /// If this reference is of a temporal type, this will return a valid temporal type reference to the type definition. Otherwise, it will return a bad temporal type reference.
        /// </summary>
        /// <param name="type">Reference to the calling object.</param>
        /// <returns>A valid temporal type reference if the definition of the reference is of a temporal type. Otherwise a bad temporal type reference.</returns>
        public static IEdmTemporalTypeReference AsTemporal(this IEdmTypeReference type)
        {
            EdmUtil.CheckArgumentNull(type, "type");
            IEdmTemporalTypeReference temporal = type as IEdmTemporalTypeReference;

            if (temporal != null)
            {
                return(temporal);
            }

            string          typeFullName = type.FullName();
            List <EdmError> errors       = new List <EdmError>(type.Errors());

            if (errors.Count == 0)
            {
                errors.AddRange(ConversionError(type.Location(), typeFullName, EdmConstants.Type_Temporal));
            }

            return(new BadTemporalTypeReference(typeFullName, type.IsNullable, errors));
        }
Example #10
0
 private static bool IsEquivalentTo(this IEdmTemporalTypeReference thisType, IEdmTemporalTypeReference otherType)
 {
     if (thisType.TypeKind() != otherType.TypeKind() || thisType.IsNullable != otherType.IsNullable)
     {
         return(false);
     }
     else
     {
         int?precision = thisType.Precision;
         int?nullable  = otherType.Precision;
         if (precision.GetValueOrDefault() != nullable.GetValueOrDefault())
         {
             return(false);
         }
         else
         {
             return(precision.HasValue == nullable.HasValue);
         }
     }
 }
Example #11
0
        public static IEdmTemporalTypeReference AsTemporal(this IEdmTypeReference type)
        {
            EdmUtil.CheckArgumentNull <IEdmTypeReference>(type, "type");
            IEdmTemporalTypeReference edmTemporalTypeReference = type as IEdmTemporalTypeReference;

            if (edmTemporalTypeReference == null)
            {
                string          str       = type.FullName();
                List <EdmError> edmErrors = new List <EdmError>(type.Errors());
                if (edmErrors.Count == 0)
                {
                    edmErrors.AddRange(EdmTypeSemantics.ConversionError(type.Location(), str, "Temporal"));
                }
                return(new BadTemporalTypeReference(str, type.IsNullable, edmErrors));
            }
            else
            {
                return(edmTemporalTypeReference);
            }
        }
Example #12
0
        /// <summary>
        /// Clones the specified type reference.
        /// </summary>
        /// <param name="typeReference">The type reference to clone.</param>
        /// <param name="nullable">true to make the cloned type reference nullable; false to make it non-nullable.</param>
        /// <returns>The cloned <see cref="IEdmTypeReference"/> instance.</returns>
        public static IEdmTypeReference Clone(this IEdmTypeReference typeReference, bool nullable)
        {
            if (typeReference == null)
            {
                return(null);
            }

            EdmTypeKind typeKind = typeReference.TypeKind();

            switch (typeKind)
            {
            case EdmTypeKind.Primitive:
                EdmPrimitiveTypeKind kind          = typeReference.PrimitiveKind();
                IEdmPrimitiveType    primitiveType = (IEdmPrimitiveType)typeReference.Definition;
                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:
                    IEdmBinaryTypeReference binaryTypeReference = (IEdmBinaryTypeReference)typeReference;
                    return(new EdmBinaryTypeReference(
                               primitiveType,
                               nullable,
                               binaryTypeReference.IsUnbounded,
                               binaryTypeReference.MaxLength));

                case EdmPrimitiveTypeKind.String:
                    IEdmStringTypeReference stringTypeReference = (IEdmStringTypeReference)typeReference;
                    return(new EdmStringTypeReference(
                               primitiveType,
                               nullable,
                               stringTypeReference.IsUnbounded,
                               stringTypeReference.MaxLength,
                               stringTypeReference.IsUnicode));

                case EdmPrimitiveTypeKind.Decimal:
                    IEdmDecimalTypeReference decimalTypeReference = (IEdmDecimalTypeReference)typeReference;
                    return(new EdmDecimalTypeReference(primitiveType, nullable, decimalTypeReference.Precision, decimalTypeReference.Scale));

                case EdmPrimitiveTypeKind.DateTimeOffset:
                case EdmPrimitiveTypeKind.Duration:
                    IEdmTemporalTypeReference temporalTypeReference = (IEdmTemporalTypeReference)typeReference;
                    return(new EdmTemporalTypeReference(primitiveType, nullable, temporalTypeReference.Precision));

                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.GeometryCollection:
                case EdmPrimitiveTypeKind.GeometryPoint:
                case EdmPrimitiveTypeKind.GeometryLineString:
                case EdmPrimitiveTypeKind.GeometryPolygon:
                case EdmPrimitiveTypeKind.GeometryMultiPolygon:
                case EdmPrimitiveTypeKind.GeometryMultiLineString:
                case EdmPrimitiveTypeKind.GeometryMultiPoint:
                    IEdmSpatialTypeReference spatialTypeReference = (IEdmSpatialTypeReference)typeReference;
                    return(new EdmSpatialTypeReference(primitiveType, nullable, spatialTypeReference.SpatialReferenceIdentifier));

                default:
                    throw new TaupoNotSupportedException("Invalid primitive type kind: " + typeKind.ToString());
                }

            case EdmTypeKind.Entity:
                return(new EdmEntityTypeReference((IEdmEntityType)typeReference.Definition, nullable));

            case EdmTypeKind.Complex:
                return(new EdmComplexTypeReference((IEdmComplexType)typeReference.Definition, nullable));

            case EdmTypeKind.Collection:
                return(new EdmCollectionTypeReference((IEdmCollectionType)typeReference.Definition));

            case EdmTypeKind.EntityReference:
                return(new EdmEntityReferenceTypeReference((IEdmEntityReferenceType)typeReference.Definition, nullable));

            case EdmTypeKind.Enum:
                return(new EdmEnumTypeReference((IEdmEnumType)typeReference.Definition, nullable));

            case EdmTypeKind.None:      // fall through
            default:
                throw new TaupoNotSupportedException("Invalid type kind: " + typeKind.ToString());
            }
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmDurationConstant"/> class.
 /// </summary>
 /// <param name="type">Type of the Duration.</param>
 /// <param name="value">Duration value represented by this value.</param>
 public EdmDurationConstant(IEdmTemporalTypeReference type, TimeSpan value)
     : base(type)
 {
     this.value = value;
 }
 public EdmDateTimeOffsetConstant(IEdmTemporalTypeReference type, DateTimeOffset value) : base(type)
 {
     this.@value = value;
 }
Example #15
0
 protected virtual void ProcessTemporalTypeReference(IEdmTemporalTypeReference reference)
 {
     this.ProcessPrimitiveTypeReference(reference);
 }
Example #16
0
 internal void WriteTemporalTypeAttributes(IEdmTemporalTypeReference reference)
 {
     WriteOptionalAttribute(CsdlConstants.Attribute_Precision, reference.Precision, EdmValueWriter.IntAsXml);
 }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmTimeOfDayConstant"/> class.
 /// </summary>
 /// <param name="type">Type of the TimeOfDay.</param>
 /// <param name="value">TimeOfDay value represented by this value.</param>
 public EdmTimeOfDayConstant(IEdmTemporalTypeReference type, TimeOfDay value)
     : base(type)
 {
     this.value = value;
 }
Example #18
0
        internal static IEdmTypeReference Clone(this IEdmTypeReference typeReference, bool nullable)
        {
            if (typeReference == null)
            {
                return(null);
            }
            switch (typeReference.TypeKind())
            {
            case EdmTypeKind.Primitive:
            {
                EdmPrimitiveTypeKind kind2      = typeReference.PrimitiveKind();
                IEdmPrimitiveType    definition = (IEdmPrimitiveType)typeReference.Definition;
                switch (kind2)
                {
                case EdmPrimitiveTypeKind.Binary:
                {
                    IEdmBinaryTypeReference reference = (IEdmBinaryTypeReference)typeReference;
                    return(new EdmBinaryTypeReference(definition, nullable, reference.IsUnbounded, reference.MaxLength, reference.IsFixedLength));
                }

                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(definition, nullable));

                case EdmPrimitiveTypeKind.DateTime:
                case EdmPrimitiveTypeKind.DateTimeOffset:
                case EdmPrimitiveTypeKind.Time:
                {
                    IEdmTemporalTypeReference reference4 = (IEdmTemporalTypeReference)typeReference;
                    return(new EdmTemporalTypeReference(definition, nullable, reference4.Precision));
                }

                case EdmPrimitiveTypeKind.Decimal:
                {
                    IEdmDecimalTypeReference reference3 = (IEdmDecimalTypeReference)typeReference;
                    return(new EdmDecimalTypeReference(definition, nullable, reference3.Precision, reference3.Scale));
                }

                case EdmPrimitiveTypeKind.String:
                {
                    IEdmStringTypeReference reference2 = (IEdmStringTypeReference)typeReference;
                    return(new EdmStringTypeReference(definition, nullable, reference2.IsUnbounded, reference2.MaxLength, reference2.IsFixedLength, reference2.IsUnicode, reference2.Collation));
                }

                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:
                {
                    IEdmSpatialTypeReference reference5 = (IEdmSpatialTypeReference)typeReference;
                    return(new EdmSpatialTypeReference(definition, nullable, reference5.SpatialReferenceIdentifier));
                }
                }
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodesCommon.EdmLibraryExtensions_Clone_PrimitiveTypeKind));
            }

            case EdmTypeKind.Entity:
                return(new EdmEntityTypeReference((IEdmEntityType)typeReference.Definition, nullable));

            case EdmTypeKind.Complex:
                return(new EdmComplexTypeReference((IEdmComplexType)typeReference.Definition, nullable));

            case EdmTypeKind.Row:
                return(new EdmRowTypeReference((IEdmRowType)typeReference.Definition, nullable));

            case EdmTypeKind.Collection:
                return(new EdmCollectionTypeReference((IEdmCollectionType)typeReference.Definition, nullable));

            case EdmTypeKind.EntityReference:
                return(new EdmEntityReferenceTypeReference((IEdmEntityReferenceType)typeReference.Definition, nullable));

            case EdmTypeKind.Enum:
                return(new EdmEnumTypeReference((IEdmEnumType)typeReference.Definition, nullable));
            }
            throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodesCommon.EdmLibraryExtensions_Clone_TypeKind));
        }
Example #19
0
		private static bool IsEquivalentTo(this IEdmTemporalTypeReference thisType, IEdmTemporalTypeReference otherType)
		{
			if (thisType.TypeKind() != otherType.TypeKind() || thisType.IsNullable != otherType.IsNullable)
			{
				return false;
			}
			else
			{
				int? precision = thisType.Precision;
				int? nullable = otherType.Precision;
				if (precision.GetValueOrDefault() != nullable.GetValueOrDefault())
				{
					return false;
				}
				else
				{
					return precision.HasValue == nullable.HasValue;
				}
			}
		}
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmDateTimeConstant"/> class.
 /// </summary>
 /// <param name="type">Type of the DateTime.</param>
 /// <param name="value">DateTime value represented by this value.</param>
 public EdmDateTimeConstant(IEdmTemporalTypeReference type, DateTime value)
     : base(type)
 {
     this.value = value;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmTimeOfDayConstant"/> class.
 /// </summary>
 /// <param name="type">Type of the TimeOfDay.</param>
 /// <param name="value">TimeOfDay value represented by this value.</param>
 public EdmTimeOfDayConstant(IEdmTemporalTypeReference type, TimeOfDay value)
     : base(type)
 {
     this.value = value;
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmDurationConstant"/> class.
 /// </summary>
 /// <param name="type">Type of the Duration.</param>
 /// <param name="value">Duration value represented by this value.</param>
 public EdmDurationConstant(IEdmTemporalTypeReference type, TimeSpan value)
     : base(type)
 {
     this.value = value;
 }
 internal void WriteTemporalTypeAttributes(IEdmTemporalTypeReference reference)
 {
     this.WriteOptionalAttribute <int?>("Precision", reference.Precision, new Func <int?, string>(EdmValueWriter.IntAsXml));
 }
Example #24
0
        public void CsdlTypeReferenceToStringTest()
        {
            const string csdl =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""AwesomeNamespace"" Alias=""Alias"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <EntityType Name=""AstonishingEntity"">
    <Key>
      <PropertyRef Name=""Id"" />
    </Key>
    <Property Name=""Id"" Type=""Int32"" Nullable=""false"" />
  </EntityType>
  <EntityType Name=""AweInspiringEntity"">
    <Key>
      <PropertyRef Name=""Id"" />
    </Key>
    <Property Name=""Id"" Type=""Int32"" Nullable=""false"" />
    <Property Name=""AstonishingID"" Type=""Int32"" />
  </EntityType>
  <ComplexType Name=""BreathtakingComplex"">
    <Property Name=""Par1"" Type=""Int32"" Nullable=""false"" />
    <Property Name=""Par2"" Type=""Int32"" Nullable=""false"" />
  </ComplexType>
  <Function Name=""Function1""><ReturnType Type=""Edm.Int32""/>
    <Parameter Name=""P1"" Type=""AwesomeNamespace.AstonishingEntity"" />
    <Parameter Name=""P2"" Type=""AwesomeNamespace.BreathtakingComplex"" />
    <Parameter Name=""P3"" Type=""AwesomeNamespace.ExaltedAssociation"" />
    <Parameter Name=""P4"" Type=""Edm.Int32"" />
    <Parameter Name=""P5"" Type=""Edm.String"" MaxLength=""128"" Unicode=""false"" />
    <Parameter Name=""P6"" Type=""Edm.Stream"" />
    <Parameter Name=""P7"" Type=""Edm.Binary"" MaxLength=""max""/>
    <Parameter Name=""P8"" Type=""Edm.DateTimeOffset"" Precision=""1"" />
    <Parameter Name=""P9"" Type=""Edm.Decimal"" Precision=""3"" Scale=""2""/>
    <Parameter Name=""P10"" Type=""Edm.Geography"" SRID=""1""  />
    <Parameter Name=""P11"" Type=""Ref(AwesomeNamespace.AstonishingEntity)"" />
    <Parameter Name=""P12"" Type=""Collection(Edm.Int32)"" />
    <Parameter Name=""P14"" Type=""AwesomeNamespace.FabulousEnum"" />
  </Function>
  <EnumType Name=""FabulousEnum"">
    <Member Name=""m1"" />
    <Member Name=""m2"" />
  </EnumType>
</Schema>";
            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(csdl)) }, out model, out errors);

            Assert.IsTrue(parsed, "parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");

            IEdmOperation operation = (IEdmOperation)(model.FindOperations("AwesomeNamespace.Function1")).First();

            IEdmEntityTypeReference          entity      = operation.FindParameter("P1").Type.AsEntity();
            IEdmComplexTypeReference         complex     = operation.FindParameter("P2").Type.AsComplex();
            IEdmTypeReference                association = operation.FindParameter("P3").Type;
            IEdmPrimitiveTypeReference       primitive   = operation.FindParameter("P4").Type.AsPrimitive();
            IEdmStringTypeReference          stringType  = operation.FindParameter("P5").Type.AsString();
            IEdmPrimitiveTypeReference       stream      = operation.FindParameter("P6").Type.AsPrimitive();
            IEdmBinaryTypeReference          binary      = operation.FindParameter("P7").Type.AsBinary();
            IEdmTemporalTypeReference        temporal    = operation.FindParameter("P8").Type.AsTemporal();
            IEdmDecimalTypeReference         decimalType = operation.FindParameter("P9").Type.AsDecimal();
            IEdmSpatialTypeReference         spatial     = operation.FindParameter("P10").Type.AsSpatial();
            IEdmEntityReferenceTypeReference entityRef   = operation.FindParameter("P11").Type.AsEntityReference();
            IEdmCollectionTypeReference      collection  = operation.FindParameter("P12").Type.AsCollection();
            IEdmEnumTypeReference            enumTypeRef = operation.FindParameter("P14").Type.AsEnum();
            IEdmTypeReference                type        = operation.FindParameter("P1").Type;

            Assert.IsFalse(association.IsBad(), "Associations cannot be types");
            Assert.IsTrue(association.Definition.IsBad(), "Associations cannot be types");
            Assert.AreEqual("[AwesomeNamespace.AstonishingEntity Nullable=True]", entity.ToString(), "To string correct");
            Assert.AreEqual("[AwesomeNamespace.BreathtakingComplex Nullable=True]", complex.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Int32 Nullable=True]", primitive.ToString(), "To string correct");
            Assert.AreEqual("[Edm.String Nullable=True MaxLength=128 Unicode=False]", stringType.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Stream Nullable=True]", stream.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Binary Nullable=True MaxLength=max]", binary.ToString(), "To string correct");
            Assert.AreEqual("[Edm.DateTimeOffset Nullable=True Precision=1]", temporal.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Decimal Nullable=True Precision=3 Scale=2]", decimalType.ToString(), "To string correct");
            Assert.AreEqual("[Edm.Geography Nullable=True SRID=1]", spatial.ToString(), "To string correct");
            Assert.AreEqual("[Collection([Edm.Int32 Nullable=True]) Nullable=True]", collection.ToString(), "To string correct");
            Assert.AreEqual("[EntityReference(AwesomeNamespace.AstonishingEntity) Nullable=True]", entityRef.ToString(), "To string correct");
            Assert.AreEqual("[AwesomeNamespace.FabulousEnum Nullable=True]", enumTypeRef.ToString(), "To string correct");
            Assert.AreEqual("[AwesomeNamespace.AstonishingEntity Nullable=True]", type.ToString(), "To string correct");
        }
 internal abstract void WriteTemporalTypeAttributes(IEdmTemporalTypeReference reference);
 private static void AppendTemporalFacets(this StringBuilder sb, IEdmTemporalTypeReference type)
 {
     if (type.Precision != null)
     {
         sb.AppendKeyValue(EdmConstants.FacetName_Precision, type.Precision.ToString());
     }
 }
 private static bool IsEquivalentTo(this IEdmTemporalTypeReference thisType, IEdmTemporalTypeReference otherType)
 {
     return thisType.TypeKind() == otherType.TypeKind() &&
            thisType.IsNullable == otherType.IsNullable &&
            thisType.Precision == otherType.Precision;
 }
Example #28
0
 protected override void ProcessTemporalTypeReference(IEdmTemporalTypeReference element)
 {
     this.schemaWriter.WriteTemporalTypeAttributes(element);
 }
		private static void AppendTemporalFacets(this StringBuilder sb, IEdmTemporalTypeReference type)
		{
			int? precision = type.Precision;
			if (precision.HasValue)
			{
				int? nullable = type.Precision;
				sb.AppendKeyValue("Precision", nullable.ToString());
			}
		}