微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 为JsonOutputFormatter构造函数提供ArrayPool对象

从.net RC2升级到RTM后,我发现需要为从ArrayPool派生的JsonOutputFormatter的构造函数提供参数.我如何获得此对象?我正在手动创建JsonOutputFormatter,因为我需要配置ReferenceLoopHandling.

我能找到的其他相关信息是这样的:
https://github.com/aspnet/Mvc/issues/4562

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

评论中:

The JsonOutputFormatter Now needs a ArrayPool when creating it,you
can pass in ArrayPool.Shared.

我还注意到ArrayPool上有一个.Create()方法.

var formatter = new JsonOutputFormatter(formatterSettings,ArrayPool<Char>.Create());

原文地址:https://www.jb51.cc/csharp/99535.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐