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


C# IEdmTypeReference.IsDate方法代码示例

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


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

示例1: ConvertToPayloadValue

        /// <summary>
        /// Converts the given primitive value defined in a type definition from the payload object.
        /// </summary>
        /// <param name="value">The given CLR value.</param>
        /// <param name="edmTypeReference">The expected type reference from model.</param>
        /// <returns>The converted payload value of the underlying type.</returns>
        public override object ConvertToPayloadValue(object value, IEdmTypeReference edmTypeReference)
        {
            if (edmTypeReference != null)
            {
                // System.DateTime is shared by *Edm.Date and Edm.DateTimeOffset.
                if (value is DateTime)
                {
                    var dateTimeValue = (DateTime)value;

                    // System.DateTime[SqlType = Date] => Edm.Library.Date
                    if (edmTypeReference.IsDate())
                    {
                        return new Date(dateTimeValue.Year, dateTimeValue.Month, dateTimeValue.Day);
                    }

                    // System.DateTime[SqlType = DateTime or DateTime2] => Edm.DateTimeOffset
                    // If DateTime.Kind equals Local, offset should equal the offset of the system's local time zone
                    if (dateTimeValue.Kind == DateTimeKind.Local)
                    {
                        return new DateTimeOffset(dateTimeValue, TimeZoneInfo.Local.GetUtcOffset(dateTimeValue));
                    }

                    return new DateTimeOffset(dateTimeValue, TimeSpan.Zero);
                }

                // System.TimeSpan is shared by *Edm.TimeOfDay and Edm.Duration:
                //   System.TimeSpan[SqlType = Time] => Edm.Library.TimeOfDay
                //   System.TimeSpan[SqlType = Time] => System.TimeSpan[EdmType = Duration]
                if (edmTypeReference.IsTimeOfDay() && value is TimeSpan)
                {
                    var timeSpanValue = (TimeSpan)value;
                    return (TimeOfDay)timeSpanValue;
                }

                // System.DateTime is converted to System.DateTimeOffset in OData Web API.
                // In order not to break ODL serialization when the EDM type is Edm.Date,
                // need to convert System.DateTimeOffset back to Edm.Date.
                if (edmTypeReference.IsDate() && value is DateTimeOffset)
                {
                    var dateTimeOffsetValue = (DateTimeOffset)value;
                    return new Date(dateTimeOffsetValue.Year, dateTimeOffsetValue.Month, dateTimeOffsetValue.Day);
                }
            }

            return base.ConvertToPayloadValue(value, edmTypeReference);
        }
开发者ID:chinadragon0515,项目名称:RESTier,代码行数:52,代码来源:RestierPayloadValueConverter.cs

示例2: ConvertToPayloadValue

        /// <summary>
        /// Converts the given primitive value defined in a type definition from the payload object.
        /// </summary>
        /// <param name="value">The given CLR value.</param>
        /// <param name="edmTypeReference">The expected type reference from model.</param>
        /// <returns>The converted payload value of the underlying type.</returns>
        /// <remarks>
        /// RESTier handles Edm.Date specially.
        /// System.DateTime values will be converted to System.DateTimeOffset in OData Web API
        /// before being passed into ODataLib for serialization. So we need to convert System.DateTimeOffset
        /// to Edm.Library.Date to avoid type validation failure in ODataLib.
        /// </remarks>
        public override object ConvertToPayloadValue(object value, IEdmTypeReference edmTypeReference)
        {
            if (edmTypeReference != null && edmTypeReference.IsDate() && value is DateTimeOffset)
            {
                var dateTimeOffsetValue = (DateTimeOffset)value;
                return new Date(dateTimeOffsetValue.Year, dateTimeOffsetValue.Month, dateTimeOffsetValue.Day);
            }

            return base.ConvertToPayloadValue(value, edmTypeReference);
        }
开发者ID:jeeshenlee,项目名称:RESTier,代码行数:22,代码来源:ODataDomainPayloadValueConverter.cs

示例3: ConvertToPayloadValue

        public override object ConvertToPayloadValue(object value, IEdmTypeReference edmTypeReference)
        {
            if (edmTypeReference != null && edmTypeReference.IsDate())
            {
                if (value is DateTimeOffset)
                {
                    DateTimeOffset dto = (DateTimeOffset)value;
                    return new Date(dto.Year, dto.Month, dto.Day);
                }
            }

            return base.ConvertToPayloadValue(value, edmTypeReference);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:13,代码来源:DateWithEfTest.cs

示例4: ConvertToPayloadValue

        /// <summary>
        /// Converts the given primitive value defined in a type definition from the payload object.
        /// </summary>
        /// <param name="value">The given CLR value.</param>
        /// <param name="edmTypeReference">The expected type reference from model.</param>
        /// <returns>The converted payload value of the underlying type.</returns>
        /// <remarks>
        /// RESTier handles Edm.Date specially.
        /// System.DateTime values will be converted to System.DateTimeOffset in OData Web API
        /// before being passed into ODataLib for serialization. So we need to convert System.DateTimeOffset
        /// to Edm.Library.Date to avoid type validation failure in ODataLib.
        /// </remarks>
        public override object ConvertToPayloadValue(object value, IEdmTypeReference edmTypeReference)
        {
            if (value is DateTime)
            {
                // System.DateTime is considered as the only mapped type for Edm.Date.
                var dateTimeValue = (DateTime)value;
                return new Date(dateTimeValue.Year, dateTimeValue.Month, dateTimeValue.Day);
            }

            if (edmTypeReference != null && edmTypeReference.IsDate() && value is DateTimeOffset)
            {
                var dateTimeOffsetValue = (DateTimeOffset)value;
                return new Date(dateTimeOffsetValue.Year, dateTimeOffsetValue.Month, dateTimeOffsetValue.Day);
            }

            return base.ConvertToPayloadValue(value, edmTypeReference);
        }
开发者ID:adestis-mh,项目名称:RESTier,代码行数:29,代码来源:RestierPayloadValueConverter.cs

示例5: TryCastDateConstantAsType

        private static bool TryCastDateConstantAsType(IEdmDateConstantExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
        {
            if (!type.IsDate())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                return false;
            }

            discoveredErrors = Enumerable.Empty<EdmError>();
            return true;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:11,代码来源:ExpressionTypeChecker.cs


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