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


C# IEdmTypeReference.IsTimeOfDay方法代码示例

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


在下文中一共展示了IEdmTypeReference.IsTimeOfDay方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TryCastTimeOfDayConstantAsType

        private static bool TryCastTimeOfDayConstantAsType(IEdmTimeOfDayConstantExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
        {
            if (!type.IsTimeOfDay())
            {
                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.IsTimeOfDay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。