• <bdo id='67hQ3'></bdo><ul id='67hQ3'></ul>

    <tfoot id='67hQ3'></tfoot>
    <legend id='67hQ3'><style id='67hQ3'><dir id='67hQ3'><q id='67hQ3'></q></dir></style></legend>

    1. <small id='67hQ3'></small><noframes id='67hQ3'>

    2. <i id='67hQ3'><tr id='67hQ3'><dt id='67hQ3'><q id='67hQ3'><span id='67hQ3'><b id='67hQ3'><form id='67hQ3'><ins id='67hQ3'></ins><ul id='67hQ3'></ul><sub id='67hQ3'></sub></form><legend id='67hQ3'></legend><bdo id='67hQ3'><pre id='67hQ3'><center id='67hQ3'></center></pre></bdo></b><th id='67hQ3'></th></span></q></dt></tr></i><div id='67hQ3'><tfoot id='67hQ3'></tfoot><dl id='67hQ3'><fieldset id='67hQ3'></fieldset></dl></div>
      1. 如何为 JObject 创建唯一的哈希码?

        时间:2023-08-23
          <tfoot id='mLlIw'></tfoot>
          • <bdo id='mLlIw'></bdo><ul id='mLlIw'></ul>

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

                  <i id='mLlIw'><tr id='mLlIw'><dt id='mLlIw'><q id='mLlIw'><span id='mLlIw'><b id='mLlIw'><form id='mLlIw'><ins id='mLlIw'></ins><ul id='mLlIw'></ul><sub id='mLlIw'></sub></form><legend id='mLlIw'></legend><bdo id='mLlIw'><pre id='mLlIw'><center id='mLlIw'></center></pre></bdo></b><th id='mLlIw'></th></span></q></dt></tr></i><div id='mLlIw'><tfoot id='mLlIw'></tfoot><dl id='mLlIw'><fieldset id='mLlIw'></fieldset></dl></div>
                  <legend id='mLlIw'><style id='mLlIw'><dir id='mLlIw'><q id='mLlIw'></q></dir></style></legend>
                    <tbody id='mLlIw'></tbody>
                  本文介绍了如何为 JObject 创建唯一的哈希码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试为 JObjects 实现缓存.

                  I'm trying to implement a cache for JObjects.

                  我很惊讶他们没有覆盖 GetHashCode 方法,因此我不能将它用作唯一键.

                  I was surprised to see that they didn't override the GetHashCode method and therefore, I can't use it as a unique key.

                  由于我的 json 非常大,我不想使用 JObject.ToString().GetHashCode 作为解决方案.

                  Since my json's are pretty large, I don't want to use JObject.ToString().GetHashCode as a solution.

                  我确实看到他们有一个名为 GetDeepHashCode 的内部方法,但该实现基于其他受保护的属性,因此,我无法复制"代码并从中创建扩展方法.

                  I did see that they have an internal method called GetDeepHashCode but the implementation is based on other protected properties and therefore, I cannot "copy" the code and create an extension method from it.

                  我也不想使用反射并调用内部 GetDeepHashCode 方法.

                  I also don't want to use reflection and invoke the internal GetDeepHashCode method.

                  我正在寻找一种为 JObject 创建唯一缓存键的方法,并且我不希望该方法在性能方面过于昂贵.

                  I'm looking for a way to create a unique cache key for a JObject and I don't want the method to be extra expensive when it comes to performance.

                  推荐答案

                  你可以使用JTokenEqualityComparer.GetHashCode(JToken token) 用于此目的.它提供对您看到的 GetDeepHashCode() 方法的访问.

                  You can use JTokenEqualityComparer.GetHashCode(JToken token) for this purpose. It provides access to the GetDeepHashCode() method you saw.

                  var obj = JToken.Parse(jsonString);
                  var comparer = new JTokenEqualityComparer();
                  var hashCode = comparer.GetHashCode(obj);
                  

                  请注意 JTokenEqualityComparer.Equals(JToken x, JToken y) 调用 JToken.DeepEquals() (来源) 所以这个比较器适合用作 IEqualityComparer<JToken> 在构建 LINQ-to-JSON 对象的哈希表或字典时,需要值的唯一性.

                  Note that JTokenEqualityComparer.Equals(JToken x, JToken y) calls JToken.DeepEquals() (source) so this comparer is suited for use as an IEqualityComparer<JToken> when constructing hash tables or dictionaries of LINQ-to-JSON objects and uniqueness of values is desired.

                  这篇关于如何为 JObject 创建唯一的哈希码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Json.net `JsonConstructor` 构造函数参数名称 下一篇:反序列化 Newtonsoft.Json 中的自定义异常

                  相关文章

                  最新文章

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

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

                    <tfoot id='X094p'></tfoot>