Exemple #1
0
        //////////////////////////////////////////////////////////////////////
        // Diff相关
        //////////////////////////////////////////////////////////////////////
        // 必须和ApplyDiff使用
        // 以new为基准,获取new相对于old不一样的部分
        // local diff = table.GetDiff(old, new)
        //  table.ApplyDiff(old, diff)
        // 这样old的就变成和new一模一样的数据
        public static LinkedHashtable GetDiff(IDictionary oldDict, IDictionary newDict)
        {
            var diff = new LinkedHashtable();

            foreach (DictionaryEntry dictionaryEntry in newDict)
            {
                var newK = dictionaryEntry.Key;
                var newV = dictionaryEntry.Value;
                if (newV is IDictionary newVDict)
                {
                    switch (newVDict.Count)
                    {
                    case 0 when(!oldDict.Contains(newK) || oldDict[newK].GetType() != newVDict.GetType() ||
                                (oldDict[newK] is IDictionary &&
                                 ((IDictionary)oldDict[newK]).Count != 0)):
                        diff[newK] = StringConst.String_New_In_Table + newVDict.GetType();
                        break;

                    default:
                    {
                        if (oldDict.Contains(newK) && oldDict[newK] is IDictionary)
                        {
                            diff[newK] = GetDiff((IDictionary)oldDict[newK], newVDict);
                        }
                        else if (!oldDict.Contains(newK) || !newVDict.Equals(oldDict[newK]))
                        {
                            diff[newK] = CloneUtil.CloneDeep(newV);
                        }
                        break;
                    }
                    }
                }
                else if (newV is IList list && oldDict.Contains(newK) && oldDict[newK] is IList)
                {
                    diff[newK] = ListUtil.GetDiff((IList)oldDict[newK], list);
                }
Exemple #2
0
 //////////////////////////////////////////////////////////////////////
 // Diff相关
 //////////////////////////////////////////////////////////////////////
 // 必须和ApplyDiff使用
 // 以new为基准,获取new相对于old不一样的部分
 // local diff = table.GetDiff(old, new)
 //  table.ApplyDiff(old, diff)
 // 这样old的就变成和new一模一样的数据
 public static LinkedHashtable GetDiff(this IList oldList, IList newList)
 {
     return(ListUtil.GetDiff(oldList, newList));
 }