mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Clean up #if hell a bit more (#2450)
* Clean up #if hell a bit more * Add missing null checks
This commit is contained in:
@@ -354,14 +354,7 @@ namespace ArchiSteamFarm.IPC {
|
||||
mvc.AddApiExplorer();
|
||||
#endif
|
||||
|
||||
#if NETFRAMEWORK
|
||||
// Add JSON formatters that will be used as default ones if no specific formatters are asked for
|
||||
mvc.AddJsonFormatters();
|
||||
|
||||
mvc.AddJsonOptions(
|
||||
#else
|
||||
mvc.AddNewtonsoftJson(
|
||||
#endif
|
||||
static options => {
|
||||
// Fix default contract resolver to use original names and not a camel case
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endif
|
||||
using System;
|
||||
@@ -42,6 +43,23 @@ namespace ArchiSteamFarm.IPC {
|
||||
return services.AddMvcCore();
|
||||
}
|
||||
|
||||
internal static IMvcCoreBuilder AddNewtonsoftJson(this IMvcCoreBuilder mvc, Action<MvcJsonOptions> setupAction) {
|
||||
if (mvc == null) {
|
||||
throw new ArgumentNullException(nameof(mvc));
|
||||
}
|
||||
|
||||
if (setupAction == null) {
|
||||
throw new ArgumentNullException(nameof(setupAction));
|
||||
}
|
||||
|
||||
// Add JSON formatters that will be used as default ones if no specific formatters are asked for
|
||||
mvc.AddJsonFormatters();
|
||||
|
||||
mvc.AddJsonOptions(setupAction);
|
||||
|
||||
return mvc;
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action<RequestLocalizationOptions> action) {
|
||||
if (services == null) {
|
||||
throw new ArgumentNullException(nameof(services));
|
||||
|
||||
Reference in New Issue
Block a user