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