コード例 #1
0
        /// <inheritdoc/>
        public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
        {
            if (messageWriter == null)
            {
                throw Error.ArgumentNull("messageWriter");
            }
            if (graph == null)
            {
                throw Error.ArgumentNull("graph");
            }

            if (graph.GetType().IsEnum)
            {
                messageWriter.WriteValue(graph.ToString());
            }
            else
            {
                if (graph is DateTime)
                {
                    messageWriter.WriteValue(ODataPrimitiveSerializer.ConvertUnsupportedDateTime((DateTime)graph,
                                                                                                 writeContext != null ? writeContext.TimeZoneInfo : null));
                }
                else
                {
                    messageWriter.WriteValue(ODataPrimitiveSerializer.ConvertUnsupportedPrimitives(graph));
                }
            }
        }
コード例 #2
0
        public void ConvertUnsupportedDateTime_NonStandardEdmPrimitives(DateTime graph, DateTimeOffset result)
        {
            // Arrange & Act
            object value = ODataPrimitiveSerializer.ConvertUnsupportedDateTime(graph, timeZoneInfo: null);

            // Assert
            DateTimeOffset actual = Assert.IsType <DateTimeOffset>(value);

            Assert.Equal(new DateTimeOffset(graph), actual);
        }
コード例 #3
0
        public void ConvertUnsupportedDateTime_NonStandardEdmPrimitives_TimeZone(DateTime graph, DateTimeOffset result)
        {
            // Arrange
            TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

            // Act
            object value = ODataPrimitiveSerializer.ConvertUnsupportedDateTime(graph, tzi);

            // Assert
            DateTimeOffset actual = Assert.IsType <DateTimeOffset>(value);

            Assert.Equal(result, actual);
        }