本文整理汇总了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);
}
示例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;
}