c# – 为JsonOutputFormatter构造函数提供ArrayPool对象
发布时间:2020-12-15 07:47:18 所属栏目:百科 来源:网络整理
导读:从.net RC2升级到RTM后,我发现需要为从ArrayPool派生的JsonOutputFormatter的构造函数提供参数.我如何获得此对象?我正在手动创建JsonOutputFormatter,因为我需要配置ReferenceLoopHandling. 我能找到的其他相关信息是这样的: https://github.com/aspnet/Mv
从.net RC2升级到RTM后,我发现需要为从ArrayPool派生的JsonOutputFormatter的构造函数提供参数.我如何获得此对象?我正在手动创建JsonOutputFormatter,因为我需要配置ReferenceLoopHandling.
我能找到的其他相关信息是这样的: public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMemoryCache(); services.AddSession(); services.AddMvc(); var formatterSettings = JsonSerializerSettingsProvider.CreateSerializerSettings(); formatterSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; JsonOutputFormatter formatter = new JsonOutputFormatter(formatterSettings,???); services.Configure<MvcOptions>(options => { options.OutputFormatters.RemoveType<JsonOutputFormatter>(); options.OutputFormatters.Insert(0,formatter); }); //etc... } 解决方法var formatter = new JsonOutputFormatter(formatterSettings,ArrayPool<Char>.Shared); Source 在评论中:
我还注意到ArrayPool上有一个.Create()方法. var formatter = new JsonOutputFormatter(formatterSettings,ArrayPool<Char>.Create()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |