<bdo id='RT8E9'></bdo><ul id='RT8E9'></ul>
    1. <i id='RT8E9'><tr id='RT8E9'><dt id='RT8E9'><q id='RT8E9'><span id='RT8E9'><b id='RT8E9'><form id='RT8E9'><ins id='RT8E9'></ins><ul id='RT8E9'></ul><sub id='RT8E9'></sub></form><legend id='RT8E9'></legend><bdo id='RT8E9'><pre id='RT8E9'><center id='RT8E9'></center></pre></bdo></b><th id='RT8E9'></th></span></q></dt></tr></i><div id='RT8E9'><tfoot id='RT8E9'></tfoot><dl id='RT8E9'><fieldset id='RT8E9'></fieldset></dl></div>

      <legend id='RT8E9'><style id='RT8E9'><dir id='RT8E9'><q id='RT8E9'></q></dir></style></legend>
    2. <tfoot id='RT8E9'></tfoot>
      1. <small id='RT8E9'></small><noframes id='RT8E9'>

        Newtonsoft 忽略属性?

        时间:2023-08-22
          <legend id='utJFx'><style id='utJFx'><dir id='utJFx'><q id='utJFx'></q></dir></style></legend>
        • <small id='utJFx'></small><noframes id='utJFx'>

          1. <i id='utJFx'><tr id='utJFx'><dt id='utJFx'><q id='utJFx'><span id='utJFx'><b id='utJFx'><form id='utJFx'><ins id='utJFx'></ins><ul id='utJFx'></ul><sub id='utJFx'></sub></form><legend id='utJFx'></legend><bdo id='utJFx'><pre id='utJFx'><center id='utJFx'></center></pre></bdo></b><th id='utJFx'></th></span></q></dt></tr></i><div id='utJFx'><tfoot id='utJFx'></tfoot><dl id='utJFx'><fieldset id='utJFx'></fieldset></dl></div>
              <tfoot id='utJFx'></tfoot>

                <bdo id='utJFx'></bdo><ul id='utJFx'></ul>

                  <tbody id='utJFx'></tbody>
                  本文介绍了Newtonsoft 忽略属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前正在使用相同的 C# DTO 通过 LoveSeat 从 CouchDB 中提取数据,我将通过 ASP MVC 控制器返回 JSON.

                  I am currently using the same C# DTOs to pull data out of CouchDB, via LoveSeat which I am going to return JSON via an ASP MVC controller.

                  我正在使用 NewtonSoft 库对我的 DTO 进行序列化,然后再通过控制器发送它们.

                  I am using the NewtonSoft library to seralise my DTOs before sending them down through the controller.

                  但是,由于 CouchDB 也使用 NewtonSoft,因此它也尊重属性级别的 NewtonSoft 属性,例如

                  However, as CouchDB also uses NewtonSoft it is also respecting the property level NewtonSoft attributes such as

                  [JsonIgnore]
                  [JsonProperty("foo")]
                  

                  有没有办法告诉 newtonsoft 库明确地忽略这些属性?LoveSeat 允许我提供自己的 IObjectSerializer 实现,这使我可以完全控制 netwonsofts JsonSerializerSettings.那么,我可以通过使用这些设置来忽略这些属性吗?

                  Is there anyway to tell the newtonsoft library to ignore these attributes explicitly? LoveSeat allows me to provide my own implementation of IObjectSerializer, which gives me full control over netwonsofts JsonSerializerSettings. So, can I ignore the attributes by using those settings ?

                  我现在看到的唯一选择是欺骗我的 DTO.虽然这并不可怕,但也不是很好.

                  I ask as the only alternative I can see at this point, is to dupe my DTOs. While not that's not terrible, it isn't great either.

                  我能看到的唯一另一种方法是将我自己版本的 Newtonsoft.Json 源代码引入我的项目中,使用不同的程序集名称等.但是这种方式肯定是疯狂的,我只会在我之前欺骗 DTO沿着这条路走.

                  The only other way I can see is to bring in my own version of the Newtonsoft.Json source into my project, with a different assembly name etc etc. But this way madness definitely lies and I will just dupe the DTOs before I go down this road.

                  推荐答案

                  我最终制作了我需要的所有属性,只需将属性添加到虚拟,并在另一个类中单独覆盖它们,并使用相关的 newtonsoft 属性.

                  I ended up making all properties I needed to only add attributes to virtual, and overriding them alone in another class, with the relevant newtonsoft attributes.

                  这允许我在从 CouchDB 反序列化并为 GET 序列化时有不同的序列化行为,而不会受到太多欺骗.两者结合很好,而且是一个奖励.无论如何我都想要对基础进行任何更改.

                  This allows me to have different serialisation behavior when de-serialising from CouchDB and serialising for a GET, without too much dupe. It is fine, and a bonus, that the two are coupled; any changes in the base i would want anyway.

                  很高兴知道我最初的问题是否可行?

                  It would still be nice to know if my original question is possible?

                  这篇关于Newtonsoft 忽略属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 C# 应用程序中导入 JsonConvert? 下一篇:如何创建 JSON.NET 日期到字符串自定义转换器

                  相关文章

                  最新文章

                    • <bdo id='TpkjV'></bdo><ul id='TpkjV'></ul>
                  1. <legend id='TpkjV'><style id='TpkjV'><dir id='TpkjV'><q id='TpkjV'></q></dir></style></legend>

                    <small id='TpkjV'></small><noframes id='TpkjV'>

                    <tfoot id='TpkjV'></tfoot>

                  2. <i id='TpkjV'><tr id='TpkjV'><dt id='TpkjV'><q id='TpkjV'><span id='TpkjV'><b id='TpkjV'><form id='TpkjV'><ins id='TpkjV'></ins><ul id='TpkjV'></ul><sub id='TpkjV'></sub></form><legend id='TpkjV'></legend><bdo id='TpkjV'><pre id='TpkjV'><center id='TpkjV'></center></pre></bdo></b><th id='TpkjV'></th></span></q></dt></tr></i><div id='TpkjV'><tfoot id='TpkjV'></tfoot><dl id='TpkjV'><fieldset id='TpkjV'></fieldset></dl></div>