-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 20 additions & 14 deletions
34
src/Microsoft.AspNetCore.OData.NewtonsoftJson/Microsoft.AspNetCore.OData.NewtonsoftJson.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
src/Microsoft.AspNetCore.OData.NewtonsoftJson/ODataNewtonsoftJsonMvcBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Query.Container; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.OData.Edm; | ||
|
||
namespace Microsoft.AspNetCore.OData.NewtonsoftJson | ||
{ | ||
/// <summary> | ||
/// Extension methods for adding OData Json converter to Newtonsoft.Json to <see cref="IMvcBuilder"/> and <see cref="IMvcCoreBuilder"/>. | ||
/// </summary> | ||
public static class ODataNewtonsoftJsonMvcBuilderExtensions | ||
{ | ||
#region IMvcBuilder | ||
/// <summary> | ||
/// Configures Newtonsoft.Json using OData Json converter. | ||
/// </summary> | ||
/// <param name="builder">The Mvc builder.</param> | ||
/// <returns>The <see cref="IMvcBuilder"/>.</returns> | ||
public static IMvcBuilder AddODataNewtonsoftJson(this IMvcBuilder builder) | ||
{ | ||
return builder.AddODataNewtonsoftJson(null); | ||
} | ||
|
||
/// <summary> | ||
/// Configures Newtonsoft.Json using OData Json converter. | ||
/// </summary> | ||
/// <param name="builder">The Mvc builder.</param> | ||
/// <param name="mapperProvider">The mapper provider.</param> | ||
/// <returns>The <see cref="IMvcBuilder"/>.</returns> | ||
public static IMvcBuilder AddODataNewtonsoftJson(this IMvcBuilder builder, | ||
Func<IEdmModel, IEdmStructuredType, IPropertyMapper> mapperProvider) | ||
{ | ||
if (builder is null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
return builder.AddNewtonsoftJson(BuildSetupAction(mapperProvider)); | ||
} | ||
#endregion | ||
|
||
#region IMvcCoreBuilder | ||
/// <summary> | ||
/// Configures Newtonsoft.Json using OData Json converter. | ||
/// </summary> | ||
/// <param name="builder">The Mvc core builder.</param> | ||
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns> | ||
public static IMvcCoreBuilder AddODataNewtonsoftJson(this IMvcCoreBuilder builder) | ||
{ | ||
return builder.AddNewtonsoftJson(null); | ||
} | ||
|
||
/// <summary> | ||
/// Configures Newtonsoft.Json using OData Json converter. | ||
/// </summary> | ||
/// <param name="builder">The Mvc core builder.</param> | ||
/// <param name="mapperProvider">The mapper provider.</param> | ||
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns> | ||
public static IMvcCoreBuilder AddODataNewtonsoftJson(this IMvcCoreBuilder builder, | ||
Func<IEdmModel, IEdmStructuredType, IPropertyMapper> mapperProvider) | ||
{ | ||
if (builder is null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
return builder.AddNewtonsoftJson(BuildSetupAction(mapperProvider)); | ||
} | ||
#endregion | ||
|
||
private static Action<MvcNewtonsoftJsonOptions> BuildSetupAction(Func<IEdmModel, IEdmStructuredType, IPropertyMapper> mapperProvider) | ||
{ | ||
Action<MvcNewtonsoftJsonOptions> odataSetupAction = opt => | ||
{ | ||
if (mapperProvider is null) | ||
{ | ||
opt.SerializerSettings.Converters.Add(new JSelectExpandWrapperConverter()); | ||
} | ||
else | ||
{ | ||
opt.SerializerSettings.Converters.Add(new JSelectExpandWrapperConverter(mapperProvider)); | ||
} | ||
opt.SerializerSettings.Converters.Add(new JDynamicTypeWrapperConverter()); | ||
opt.SerializerSettings.Converters.Add(new JPageResultValueConverter()); | ||
opt.SerializerSettings.Converters.Add(new JSingleResultValueConverter()); | ||
}; | ||
|
||
return odataSetupAction; | ||
} | ||
} | ||
} |
81 changes: 0 additions & 81 deletions
81
src/Microsoft.AspNetCore.OData.NewtonsoftJson/ODataNewtonsoftServiceCollectionExtensions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.