Skip to content

Commit

Permalink
Add ODataNullValueExtensions and use it during serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed May 1, 2023
1 parent a10bd2a commit 3312ab4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
16 changes: 16 additions & 0 deletions src/Microsoft.AspNetCore.OData/Edm/ODataNullValueExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------------
// <copyright file="ODataNullValueExtensions.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------

using Microsoft.OData;

namespace Microsoft.AspNetCore.OData.Edm
{
internal class ODataNullValueExtensions
{
public static readonly ODataNullValue NullValue = new ODataNullValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReferen
ODataEnumValue value = CreateODataEnumValue(graph, expectedType.AsEnum(), writeContext);
if (value == null)
{
return new ODataNullValue();
return ODataNullValueExtensions.NullValue;
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.OData.Common;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.OData.Edm;
using Microsoft.OData;
using Microsoft.OData.Edm;

Expand Down Expand Up @@ -65,7 +64,7 @@ public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReferen
ODataPrimitiveValue value = CreateODataPrimitiveValue(graph, expectedType.AsPrimitive(), writeContext);
if (value == null)
{
return new ODataNullValue();
return ODataNullValueExtensions.NullValue;
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private static IEnumerable<ODataProperty> CreateODataPropertiesFromDynamicType(E
property = new ODataProperty
{
Name = prop.Key,
Value = new ODataNullValue()
Value = ODataNullValueExtensions.NullValue
};
}
else
Expand Down Expand Up @@ -618,7 +618,7 @@ public virtual void AppendDynamicProperties(ODataResource resource, SelectExpand
dynamicProperties.Add(new ODataProperty
{
Name = dynamicProperty.Key,
Value = new ODataNullValue()
Value = ODataNullValueExtensions.NullValue
});

continue;
Expand Down
16 changes: 1 addition & 15 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,20 +1102,6 @@
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateTime; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsDateOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.DateOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.TimeOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a TimeOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeSpan(System.Type)">
<summary>
Determine if a type is a TimeSpan.
Expand Down Expand Up @@ -5907,7 +5893,7 @@
<summary>
Read OData item.
</summary>
<param name="reader">The odata reader.</param>
<param name="reader">The OData reader.</param>
<param name="itemsStack">The item stack.</param>
<param name="topLevelItem">The top level item.</param>
</member>
Expand Down

0 comments on commit 3312ab4

Please sign in to comment.