本文整理汇总了C#中IEdmPrimitiveTypeReference.IsDateTimeOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmPrimitiveTypeReference.IsDateTimeOffset方法的具体用法?C# IEdmPrimitiveTypeReference.IsDateTimeOffset怎么用?C# IEdmPrimitiveTypeReference.IsDateTimeOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmPrimitiveTypeReference
的用法示例。
在下文中一共展示了IEdmPrimitiveTypeReference.IsDateTimeOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateODataPrimitiveValue
/// <summary>
/// Creates an <see cref="ODataPrimitiveValue"/> for the object represented by <paramref name="graph"/>.
/// </summary>
/// <param name="graph">The primitive value.</param>
/// <param name="primitiveType">The EDM primitive type of the value.</param>
/// <param name="writeContext">The serializer write context.</param>
/// <returns>The created <see cref="ODataPrimitiveValue"/>.</returns>
public override ODataPrimitiveValue CreateODataPrimitiveValue(
object graph,
IEdmPrimitiveTypeReference primitiveType,
ODataSerializerContext writeContext)
{
// The EDM type of the "graph" would override the EDM type of the property when
// OData Web API infers the primitiveType. Thus for "graph" of System.DateTime,
// the primitiveType is always Edm.DateTimeOffset.
//
// In EF, System.DateTime is used for SqlDate, SqlDateTime and SqlDateTime2.
// All of them have no time zone information thus it is safe to clear the time
// zone when converting the "graph" to a DateTimeOffset.
if (primitiveType != null && primitiveType.IsDateTimeOffset() && graph is DateTime)
{
// If DateTime.Kind equals Local, offset should equal the offset of the system's local time zone
if (((DateTime)graph).Kind == DateTimeKind.Local)
{
graph = new DateTimeOffset((DateTime)graph, TimeZoneInfo.Local.GetUtcOffset((DateTime)graph));
}
else
{
graph = new DateTimeOffset((DateTime)graph, TimeSpan.Zero);
}
}
return base.CreateODataPrimitiveValue(graph, primitiveType, writeContext);
}