Exemplo n.º 1
0
        /// <summary>
        /// 设置分组(嵌套)对象
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="groupJsonPropertyName"></param>
        public void SetGroupObject(object obj, string groupJsonPropertyName)
        {
            if (jsonPropertyName.Equals(groupJsonPropertyName))
            {
                //分组路径相同,直接合并
                JToken jToken = JToken.FromObject(obj);
                IDictionary <string, object> map = new Dictionary <string, object>();
                cacheJsonHelper.ConvertNotNestedMapByJToken(jToken, ref map);

                cacheSettingDictionary = cacheSettingDictionary.Concat(map)
                                         .GroupBy(d => d.Key)
                                         .ToDictionary(kv => kv.Key, kv => kv.First().Value);
            }
            else
            {
                //直接将Object设置到公用的JsonHelper里
                cacheJsonHelper.ConcatObject(obj, groupJsonPropertyName);
                cacheSettingDictionary = cacheJsonHelper.ConvertNotNestedMap(jsonPropertyName);
            }
        }