久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

        <bdo id='I0VNh'></bdo><ul id='I0VNh'></ul>
    2. <small id='I0VNh'></small><noframes id='I0VNh'>

      <legend id='I0VNh'><style id='I0VNh'><dir id='I0VNh'><q id='I0VNh'></q></dir></style></legend>

      1. JSON.Net:強(qiáng)制序列化所有私有字段和子類中的所有

        JSON.Net: Force serialization of all private fields and all fields in sub-classes(JSON.Net:強(qiáng)制序列化所有私有字段和子類中的所有字段)
      2. <small id='75Yfl'></small><noframes id='75Yfl'>

          <bdo id='75Yfl'></bdo><ul id='75Yfl'></ul>
        • <i id='75Yfl'><tr id='75Yfl'><dt id='75Yfl'><q id='75Yfl'><span id='75Yfl'><b id='75Yfl'><form id='75Yfl'><ins id='75Yfl'></ins><ul id='75Yfl'></ul><sub id='75Yfl'></sub></form><legend id='75Yfl'></legend><bdo id='75Yfl'><pre id='75Yfl'><center id='75Yfl'></center></pre></bdo></b><th id='75Yfl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='75Yfl'><tfoot id='75Yfl'></tfoot><dl id='75Yfl'><fieldset id='75Yfl'></fieldset></dl></div>
              <tbody id='75Yfl'></tbody>

                1. <legend id='75Yfl'><style id='75Yfl'><dir id='75Yfl'><q id='75Yfl'></q></dir></style></legend>

                  <tfoot id='75Yfl'></tfoot>
                2. 本文介紹了JSON.Net:強(qiáng)制序列化所有私有字段和子類中的所有字段的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有一個(gè)包含幾個(gè)不同類的類,我將這些類中的信息發(fā)送給客戶,但我不想將它們?nèi)堪l(fā)送出去,所以有些是私有的,有些有 [JsonObject(MemberSerialization.OptIn)] 標(biāo)志等

                  I have a class with several different classes and I send the information in these classes out to clients but I don't want to send them all out so some are private, some have the [JsonObject(MemberSerialization.OptIn)] flag etc.

                  但是,現(xiàn)在我想在需要關(guān)閉服務(wù)器時(shí)以及每 12 小時(shí)(我不想使用數(shù)據(jù)庫(kù))備份所有這些對(duì)象,所以我想做的(如果可能的話)是強(qiáng)制 JSON.Net Serializer 轉(zhuǎn)換對(duì)象和屬于該對(duì)象的所有對(duì)象.

                  However, now I want to do a backup of all these objects when I need to shutdown the server and every 12 hours (I don't want to use a database) so what I want to do (if possible) is to force the JSON.Net Serializer to convert the object and all the object belonging to that object.

                  例如:

                  class Foo
                  {
                    public int Number;
                    private string name;
                    private PrivateObject po = new PrivateObject();
                  
                    public string ToJSON()
                    { /* Serialize my public field, my property and the object PrivateObject */ }
                  }
                  

                  我嘗試了這段代碼(即使它已經(jīng)過(guò)時(shí)),但它沒(méi)有序列化與我的對(duì)象相關(guān)的對(duì)象:

                  I tried this code (even though it's obsolete) but it doesn't Serialize the objects related to my object:

                  Newtonsoft.Json.JsonSerializerSettings jss = new Newtonsoft.Json.JsonSerializerSettings();
                  
                  Newtonsoft.Json.Serialization.DefaultContractResolver dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver();
                  dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
                  jss.ContractResolver = dcr;
                  
                  return Newtonsoft.Json.JsonConvert.SerializeObject(this, jss);
                  

                  推薦答案

                  這應(yīng)該可行:

                  var settings = new JsonSerializerSettings() { ContractResolver = new MyContractResolver() };
                  var json = JsonConvert.SerializeObject(obj, settings);
                  

                  <小時(shí)>

                  public class MyContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver
                  {
                      protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
                      {
                          var props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                                          .Select(p => base.CreateProperty(p, memberSerialization))
                                      .Union(type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                                                 .Select(f => base.CreateProperty(f, memberSerialization)))
                                      .ToList();
                          props.ForEach(p => { p.Writable = true; p.Readable = true; });
                          return props;
                      }
                  }
                  

                  這篇關(guān)于JSON.Net:強(qiáng)制序列化所有私有字段和子類中的所有字段的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時(shí)忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標(biāo)簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯(cuò)誤的 XML)
                    <bdo id='1yUaY'></bdo><ul id='1yUaY'></ul>
                      <tbody id='1yUaY'></tbody>
                    • <small id='1yUaY'></small><noframes id='1yUaY'>

                      1. <legend id='1yUaY'><style id='1yUaY'><dir id='1yUaY'><q id='1yUaY'></q></dir></style></legend>

                        1. <i id='1yUaY'><tr id='1yUaY'><dt id='1yUaY'><q id='1yUaY'><span id='1yUaY'><b id='1yUaY'><form id='1yUaY'><ins id='1yUaY'></ins><ul id='1yUaY'></ul><sub id='1yUaY'></sub></form><legend id='1yUaY'></legend><bdo id='1yUaY'><pre id='1yUaY'><center id='1yUaY'></center></pre></bdo></b><th id='1yUaY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1yUaY'><tfoot id='1yUaY'></tfoot><dl id='1yUaY'><fieldset id='1yUaY'></fieldset></dl></div>
                        2. <tfoot id='1yUaY'></tfoot>
                          • 主站蜘蛛池模板: 免费一级毛片 | 91精品国产一区二区三区 | 伊人伊成久久人综合网站 | 国产精品国产三级国产aⅴ原创 | 欧美一级二级三级视频 | 一级在线观看 | 大乳boobs巨大吃奶挤奶 | 精品视频在线播放 | 免费国产视频 | 精品久久国产老人久久综合 | 日本精品视频 | 一区二区三区视频 | 欧美日韩国产一区二区 | 日韩在线精品 | 亚洲成人一区二区 | 91久久国产综合久久91精品网站 | 在线国产小视频 | 老司机成人在线 | 亚洲一区视频在线播放 | 精品一区二区三区免费视频 | 欧美一页 | 欧美色专区 | 国产精品视频免费看 | 中文字幕日韩欧美 | 国产一区 | 在线三级网址 | 国产精品毛片一区二区在线看 | 日韩电影一区二区三区 | 国产精品免费小视频 | 精品一区二区久久久久久久网站 | 久久精选| 亚洲女人的天堂 | 一区二区三区免费观看 | 台湾a级理论片在线观看 | 91麻豆精品国产91久久久更新资源速度超快 | 久久久久久中文字幕 | 一区二区三区不卡视频 | 中文字幕在线观看第一页 | 自拍视频网站 | 一级毛片视频在线 | 国产精品视频不卡 |