当前位置: 首页>>代码示例>>C#>>正文


C# IEdmPrimitiveTypeReference.PrimitiveKind方法代码示例

本文整理汇总了C#中IEdmPrimitiveTypeReference.PrimitiveKind方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmPrimitiveTypeReference.PrimitiveKind方法的具体用法?C# IEdmPrimitiveTypeReference.PrimitiveKind怎么用?C# IEdmPrimitiveTypeReference.PrimitiveKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmPrimitiveTypeReference的用法示例。


在下文中一共展示了IEdmPrimitiveTypeReference.PrimitiveKind方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValueTypeMatchesJsonType

        /// <summary>
        /// Determines if the given primitive value is of a basic type where we can rely on just the JSON representation to convey type information.
        /// If so, we don't have to write the type name.
        /// </summary>
        /// <param name="primitiveValue">The primitive value in question.</param>
        /// <param name="valueTypeReference">The type of the primitive value.</param>
        /// <returns>true if the given primitive value is of a basic JSON type, false otherwise.</returns>
        internal static bool ValueTypeMatchesJsonType(ODataPrimitiveValue primitiveValue, IEdmPrimitiveTypeReference valueTypeReference)
        {
#if ODATALIB
#endif

            switch (valueTypeReference.PrimitiveKind())
            {
                // If the value being serialized is of a basic type where we can rely on just the JSON representation to convey type information, then never write the type name.
                case EdmPrimitiveTypeKind.Int32:
                case EdmPrimitiveTypeKind.String:
                case EdmPrimitiveTypeKind.Boolean:
                    return true;

                case EdmPrimitiveTypeKind.Double:
                    double doubleValue = (double)primitiveValue.Value;

                    // If a double value is positive infinity, negative infinity, or NaN, we serialize the double as a string.
                    // Thus the reader can't infer the type from the JSON representation, and we must write the type name explicitly 
                    // (i.e., if the property is open or the property type is assumed to be unknown, as is the case when writing in full metadata mode).
                    return !IsDoubleValueSerializedAsString(doubleValue);
                
                default:
                    return false;
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:JsonSharedUtils.cs

示例2: ConvertToTaupoPrimitiveDataType

        public static DataType ConvertToTaupoPrimitiveDataType(IEdmPrimitiveTypeReference edmPrimitiveTypeReference)
        {
            PrimitiveDataType result = null;
            EdmPrimitiveTypeKind primitiveKind = edmPrimitiveTypeReference.PrimitiveKind();
            if (!facetlessDataTypeLookup.TryGetValue(primitiveKind, out result))
            {
                switch (primitiveKind)
                {
                    case EdmPrimitiveTypeKind.Binary:
                        var edmBinary = edmPrimitiveTypeReference.AsBinary();
                        result = EdmDataTypes.Binary(edmBinary.MaxLength);
                        break;

                    case EdmPrimitiveTypeKind.DateTimeOffset:
                        var edmDateTimeOffset = edmPrimitiveTypeReference.AsTemporal();
                        result = EdmDataTypes.DateTimeOffset(edmDateTimeOffset.Precision);
                        break;

                    case EdmPrimitiveTypeKind.Decimal:
                        var edmDecimal = edmPrimitiveTypeReference.AsDecimal();
                        result = EdmDataTypes.Decimal(edmDecimal.Precision, edmDecimal.Scale);
                        break;

                    case EdmPrimitiveTypeKind.String:
                        var edmString = edmPrimitiveTypeReference.AsString();
                        var maxLength = edmString.MaxLength;
                        if (edmString.IsUnbounded == true)
                        {
                            maxLength = MaxLengthMaxTaupoDefaultValue; 
                        }

                        result = EdmDataTypes.String(maxLength, edmString.IsUnicode);
                        break;

                    case EdmPrimitiveTypeKind.Duration:
                        var edmTime = edmPrimitiveTypeReference.AsTemporal();
                        result = EdmDataTypes.Time(edmTime.Precision);
                        break;

                    default:
                        throw new TaupoInvalidOperationException("unexpected Edm Primitive Type Kind: " + primitiveKind);
                }
            }

            return result.Nullable(edmPrimitiveTypeReference.IsNullable);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:46,代码来源:EdmToTaupoPrimitiveDataTypeConverter.cs

示例3: ReadValueImplementation

 private object ReadValueImplementation(IEdmPrimitiveTypeReference expectedPrimitiveTypeReference)
 {
     bool flag;
     if (expectedPrimitiveTypeReference == null)
     {
         flag = this.readerPayloadKind == ODataPayloadKind.BinaryValue;
     }
     else if (expectedPrimitiveTypeReference.PrimitiveKind() == EdmPrimitiveTypeKind.Binary)
     {
         flag = true;
     }
     else
     {
         flag = false;
     }
     if (flag)
     {
         return this.ReadBinaryValue();
     }
     this.textReader = (this.encoding == null) ? new StreamReader(this.stream) : new StreamReader(this.stream, this.encoding);
     return this.ReadRawValue(expectedPrimitiveTypeReference);
 }
开发者ID:nickchal,项目名称:pash,代码行数:22,代码来源:ODataRawInputContext.cs

示例4: ReadValueImplementation

        /// <summary>
        /// Read a top-level value.
        /// </summary>
        /// <param name="expectedPrimitiveTypeReference">The expected primitive type for the value to be read; null if no expected type is available.</param>
        /// <returns>An <see cref="object"/> representing the read value.</returns>
        private object ReadValueImplementation(IEdmPrimitiveTypeReference expectedPrimitiveTypeReference)
        {
            // if an expected primitive type is specified it trumps the content type/reader payload kind
            bool readBinary;
            if (expectedPrimitiveTypeReference == null)
            {
                readBinary = this.readerPayloadKind == ODataPayloadKind.BinaryValue;
            }
            else
            {
                if (expectedPrimitiveTypeReference.PrimitiveKind() == EdmPrimitiveTypeKind.Binary)
                {
                    readBinary = true;
                }
                else
                {
                    readBinary = false;
                }
            }

            if (readBinary)
            {
                return this.ReadBinaryValue();
            }
            else
            {
                Debug.Assert(this.textReader == null, "this.textReader == null");
                this.textReader = this.encoding == null ? new StreamReader(this.stream) : new StreamReader(this.stream, this.encoding);
                return this.ReadRawValue(expectedPrimitiveTypeReference);
            }
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:36,代码来源:ODataRawInputContext.cs

示例5: ConvertStringToPrimitive

        /// <summary>
        /// Converts a string to a primitive value.
        /// </summary>
        /// <param name="text">The string text to convert.</param>
        /// <param name="targetTypeReference">Type to convert the string to.</param>
        /// <returns>The value converted to the target type.</returns>
        /// <remarks>This method does not convert null value.</remarks>
        internal static object ConvertStringToPrimitive(string text, IEdmPrimitiveTypeReference targetTypeReference)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(text != null, "text != null");
            Debug.Assert(targetTypeReference != null, "targetTypeReference != null");

            try
            {
                EdmPrimitiveTypeKind primitiveKind = targetTypeReference.PrimitiveKind();

                switch (primitiveKind)
                {
                    case EdmPrimitiveTypeKind.Binary:
                        return Convert.FromBase64String(text);
                    case EdmPrimitiveTypeKind.Boolean:
                        return ConvertXmlBooleanValue(text);
                    case EdmPrimitiveTypeKind.Byte:
                        return XmlConvert.ToByte(text);
                    case EdmPrimitiveTypeKind.DateTime:
                        return PlatformHelper.ConvertStringToDateTime(text);
                    case EdmPrimitiveTypeKind.DateTimeOffset:
                        return XmlConvert.ToDateTimeOffset(text);
                    case EdmPrimitiveTypeKind.Decimal:
                        return XmlConvert.ToDecimal(text);
                    case EdmPrimitiveTypeKind.Double:
                        return XmlConvert.ToDouble(text);
                    case EdmPrimitiveTypeKind.Guid:
                        return new Guid(text);
                    case EdmPrimitiveTypeKind.Int16:
                        return XmlConvert.ToInt16(text);
                    case EdmPrimitiveTypeKind.Int32:
                        return XmlConvert.ToInt32(text);
                    case EdmPrimitiveTypeKind.Int64:
                        return XmlConvert.ToInt64(text);
                    case EdmPrimitiveTypeKind.SByte:
                        return XmlConvert.ToSByte(text);
                    case EdmPrimitiveTypeKind.Single:
                        return XmlConvert.ToSingle(text);
                    case EdmPrimitiveTypeKind.String:
                        return text;
                    case EdmPrimitiveTypeKind.Time:
                        return XmlConvert.ToTimeSpan(text);
                    case EdmPrimitiveTypeKind.Stream:
                    case EdmPrimitiveTypeKind.None:
                    case EdmPrimitiveTypeKind.Geography:
                    case EdmPrimitiveTypeKind.GeographyCollection:
                    case EdmPrimitiveTypeKind.GeographyPoint:
                    case EdmPrimitiveTypeKind.GeographyLineString:
                    case EdmPrimitiveTypeKind.GeographyPolygon:
                    case EdmPrimitiveTypeKind.GeometryCollection:
                    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:
                    default:
                        // Note that Astoria supports XElement and Binary as well, but they are serialized as string or byte[]
                        // and the metadata will actually talk about string and byte[] as well. Astoria will perform the conversion if necessary.
                        throw new ODataException(Strings.General_InternalError(InternalErrorCodes.AtomValueUtils_ConvertStringToPrimitive));
                }
            }
            catch (Exception e)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw ReaderValidationUtils.GetPrimitiveTypeConversionException(targetTypeReference, e);
            }
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:83,代码来源:AtomValueUtils.cs

示例6: AppendFacets

 private static void AppendFacets(this StringBuilder sb, IEdmPrimitiveTypeReference type)
 {
     switch (type.PrimitiveKind())
     {
         case EdmPrimitiveTypeKind.Binary:
             sb.AppendBinaryFacets(type.AsBinary());
             break;
         case EdmPrimitiveTypeKind.Decimal:
             sb.AppendDecimalFacets(type.AsDecimal());
             break;
         case EdmPrimitiveTypeKind.String:
             sb.AppendStringFacets(type.AsString());
             break;
         case EdmPrimitiveTypeKind.Time:
         case EdmPrimitiveTypeKind.DateTime:
         case EdmPrimitiveTypeKind.DateTimeOffset:
             sb.AppendTemporalFacets(type.AsTemporal());
             break;
         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:
             sb.AppendSpatialFacets(type.AsSpatial());
             break;
     }
 }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:38,代码来源:ToTraceStringExtensionMethods.cs

示例7: IsEquivalentTo

        private static bool IsEquivalentTo(this IEdmPrimitiveTypeReference thisType, IEdmPrimitiveTypeReference otherType)
        {
            EdmPrimitiveTypeKind thisTypePrimitiveKind = thisType.PrimitiveKind();
            if (thisTypePrimitiveKind != otherType.PrimitiveKind())
            {
                return false;
            }

            switch (thisTypePrimitiveKind)
            {
                case EdmPrimitiveTypeKind.Binary:
                    return ((IEdmBinaryTypeReference)thisType).IsEquivalentTo((IEdmBinaryTypeReference)otherType);
                case EdmPrimitiveTypeKind.Decimal:
                    return ((IEdmDecimalTypeReference)thisType).IsEquivalentTo((IEdmDecimalTypeReference)otherType);
                case EdmPrimitiveTypeKind.String:
                    return ((IEdmStringTypeReference)thisType).IsEquivalentTo((IEdmStringTypeReference)otherType);
                case EdmPrimitiveTypeKind.Time:
                case EdmPrimitiveTypeKind.DateTime:
                case EdmPrimitiveTypeKind.DateTimeOffset:
                    return ((IEdmTemporalTypeReference)thisType).IsEquivalentTo((IEdmTemporalTypeReference)otherType);
                default:
                    if (thisTypePrimitiveKind.IsSpatial())
                    {
                        return ((IEdmSpatialTypeReference)thisType).IsEquivalentTo((IEdmSpatialTypeReference)otherType);
                    }
                    else
                    {
                        return thisType.IsNullable == otherType.IsNullable &&
                                thisType.Definition.IsEquivalentTo(otherType.Definition);
                    }
            }
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:32,代码来源:EdmElementComparer.cs

示例8: ConvertStringToPrimitive

        internal static object ConvertStringToPrimitive(string text, IEdmPrimitiveTypeReference targetTypeReference)
        {
            object obj2;
            try
            {
                switch (targetTypeReference.PrimitiveKind())
                {
                    case EdmPrimitiveTypeKind.Binary:
                        return Convert.FromBase64String(text);

                    case EdmPrimitiveTypeKind.Boolean:
                        return XmlConvert.ToBoolean(text);

                    case EdmPrimitiveTypeKind.Byte:
                        return XmlConvert.ToByte(text);

                    case EdmPrimitiveTypeKind.DateTime:
                        return Microsoft.Data.OData.PlatformHelper.ConvertStringToDateTime(text);

                    case EdmPrimitiveTypeKind.DateTimeOffset:
                        return XmlConvert.ToDateTimeOffset(text);

                    case EdmPrimitiveTypeKind.Decimal:
                        return XmlConvert.ToDecimal(text);

                    case EdmPrimitiveTypeKind.Double:
                        return XmlConvert.ToDouble(text);

                    case EdmPrimitiveTypeKind.Guid:
                        return new Guid(text);

                    case EdmPrimitiveTypeKind.Int16:
                        return XmlConvert.ToInt16(text);

                    case EdmPrimitiveTypeKind.Int32:
                        return XmlConvert.ToInt32(text);

                    case EdmPrimitiveTypeKind.Int64:
                        return XmlConvert.ToInt64(text);

                    case EdmPrimitiveTypeKind.SByte:
                        return XmlConvert.ToSByte(text);

                    case EdmPrimitiveTypeKind.Single:
                        return XmlConvert.ToSingle(text);

                    case EdmPrimitiveTypeKind.String:
                        return text;

                    case EdmPrimitiveTypeKind.Time:
                        return XmlConvert.ToTimeSpan(text);
                }
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.AtomValueUtils_ConvertStringToPrimitive));
            }
            catch (Exception exception)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(exception))
                {
                    throw;
                }
                throw ReaderValidationUtils.GetPrimitiveTypeConversionException(targetTypeReference, exception);
            }
            return obj2;
        }
开发者ID:nickchal,项目名称:pash,代码行数:64,代码来源:AtomValueUtils.cs

示例9: IsEquivalentTo

		private static bool IsEquivalentTo(this IEdmPrimitiveTypeReference thisType, IEdmPrimitiveTypeReference otherType)
		{
			EdmPrimitiveTypeKind edmPrimitiveTypeKind = thisType.PrimitiveKind();
			if (edmPrimitiveTypeKind == otherType.PrimitiveKind())
			{
				EdmPrimitiveTypeKind edmPrimitiveTypeKind1 = edmPrimitiveTypeKind;
				switch (edmPrimitiveTypeKind1)
				{
					case EdmPrimitiveTypeKind.Binary:
					{
						return thisType.IsEquivalentTo((IEdmBinaryTypeReference)otherType);
					}
					case EdmPrimitiveTypeKind.Boolean:
					case EdmPrimitiveTypeKind.Byte:
					{
						if (edmPrimitiveTypeKind.IsSpatial())
						{
							break;
						}
						if (thisType.IsNullable != otherType.IsNullable)
						{
							return false;
						}
						else
						{
							return thisType.Definition.IsEquivalentTo(otherType.Definition);
						}
					}
					case EdmPrimitiveTypeKind.DateTime:
					case EdmPrimitiveTypeKind.DateTimeOffset:
					{
						return thisType.IsEquivalentTo((IEdmTemporalTypeReference)otherType);
					}
					case EdmPrimitiveTypeKind.Decimal:
					{
						return thisType.IsEquivalentTo((IEdmDecimalTypeReference)otherType);
					}
					default:
					{
						if (edmPrimitiveTypeKind1 == EdmPrimitiveTypeKind.String)
						{
							return thisType.IsEquivalentTo((IEdmStringTypeReference)otherType);
						}
						else if (edmPrimitiveTypeKind1 == EdmPrimitiveTypeKind.Stream)
						{
							if (edmPrimitiveTypeKind.IsSpatial())
							{
								break;
							}
							if (thisType.IsNullable != otherType.IsNullable)
							{
								return false;
							}
							else
							{
								return thisType.Definition.IsEquivalentTo(otherType.Definition);
							}
						}
						else if (edmPrimitiveTypeKind1 == EdmPrimitiveTypeKind.Time)
						{
							return thisType.IsEquivalentTo((IEdmTemporalTypeReference)otherType);
						}
						if (edmPrimitiveTypeKind.IsSpatial())
						{
							break;
						}
						if (thisType.IsNullable != otherType.IsNullable)
						{
							return false;
						}
						else
						{
							return thisType.Definition.IsEquivalentTo(otherType.Definition);
						}
					}
				}
				return thisType.IsEquivalentTo((IEdmSpatialTypeReference)otherType);
			}
			else
			{
				return false;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:83,代码来源:EdmElementComparer.cs

示例10: AppendFacets

		private static void AppendFacets(this StringBuilder sb, IEdmPrimitiveTypeReference type)
		{
			EdmPrimitiveTypeKind edmPrimitiveTypeKind = type.PrimitiveKind();
			switch (edmPrimitiveTypeKind)
			{
				case EdmPrimitiveTypeKind.Binary:
				{
					sb.AppendBinaryFacets(type.AsBinary());
					return;
				}
				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;
				}
				case EdmPrimitiveTypeKind.DateTime:
				case EdmPrimitiveTypeKind.DateTimeOffset:
				case EdmPrimitiveTypeKind.Time:
				{
					sb.AppendTemporalFacets(type.AsTemporal());
					return;
				}
				case EdmPrimitiveTypeKind.Decimal:
				{
					sb.AppendDecimalFacets(type.AsDecimal());
					return;
				}
				case EdmPrimitiveTypeKind.String:
				{
					sb.AppendStringFacets(type.AsString());
					return;
				}
				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:
				{
					sb.AppendSpatialFacets(type.AsSpatial());
					return;
				}
				default:
				{
					return;
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:66,代码来源:ToTraceStringExtensionMethods.cs


注:本文中的IEdmPrimitiveTypeReference.PrimitiveKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。