Exemplo n.º 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);
                }
Exemplo n.º 2
0
 /// <summary>
 ///   将list[index1]和list[index2]交换
 /// </summary>
 public static void Swap <T>(this List <T> self, int index1, int index2)
 {
     ListUtil.Swap(self, index1, self, index2);
 }
Exemplo n.º 3
0
 //两个table是否不一样
 public static bool IsDiff(this IList oldList, IList newList)
 {
     return(ListUtil.IsDiff(oldList, newList));
 }
Exemplo n.º 4
0
 // 必须和ApplyDiff使用
 // 以new为基准,获取new中有,但old中没有的
 // local diff = table.GetNotExist(old, new)
 // table.ApplyDiff(old, diff)
 // 这样old就有new中的字段
 public static LinkedHashtable GetNotExist(this IList oldList, IList newList)
 {
     return(ListUtil.GetNotExist(oldList, newList));
 }
Exemplo n.º 5
0
 // table.ApplyDiff(old, diff)
 // 将diff中的东西应用到old中
 // 重要:当为Array的时候,需要重新赋值;List的时候,可以不需要重新赋值
 public static IList ApplyDiff(this IList oldList, LinkedHashtable diffDict)
 {
     return(ListUtil.ApplyDiff(oldList, diffDict));
 }