⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collectionhelper.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Utils
{
    using System;
    using System.Collections.Generic;

    public static class CollectionHelper
    {
        private static int KeyValueArrayComparison<T, TContext>(KeyValuePair<T, TContext> x, KeyValuePair<T, TContext> y) where T: IComparable
        {
            if (x.get_Key() != null)
            {
                return x.get_Key().CompareTo(y.get_Key());
            }
            if (y.get_Key() == null)
            {
                return 0;
            }
            return -1;
        }

        public static RefreshResult<T, TContext> RefreshCollection<T, TContext>(T[] colCurrent, KeyValuePair<T, TContext>[] colNew, bool includeUpdate) where T: IComparable
        {
            RefreshResult<T, TContext> result = new RefreshResult<T, TContext>(Math.Max(colCurrent.Length, colNew.Length));
            int index = 0;
            int num2 = 0;
            Array.Sort<T>(colCurrent);
            Array.Sort<KeyValuePair<T, TContext>>(colNew, new Comparison<KeyValuePair<T, TContext>>(null, (IntPtr) KeyValueArrayComparison<T, TContext>));
            for (index = 0; index < colCurrent.Length; index++)
            {
                KeyValuePair<T, TContext> pair;
                T local = colCurrent[index];
                if (num2 < colNew.Length)
                {
                    goto Label_00CB;
                }
                result.ToDelete.Add(local);
                continue;
            Label_0053:
                pair = colNew[num2];
                T local2 = pair.get_Key();
                int num3 = local.CompareTo(local2);
                if (num3 == 0)
                {
                    if (includeUpdate)
                    {
                        result.ToUpdate.Add(local, pair.get_Value());
                    }
                    num2++;
                    continue;
                }
                if (num3 < 0)
                {
                    result.ToDelete.Add(local);
                    continue;
                }
                result.ToAdd.Add(local2, pair.get_Value());
                num2++;
            Label_00CB:
                if (num2 < colNew.Length)
                {
                    goto Label_0053;
                }
            }
            while (num2 < colNew.Length)
            {
                KeyValuePair<T, TContext> pair2 = colNew[num2];
                result.ToAdd.Add(pair2.get_Key(), pair2.get_Value());
                num2++;
            }
            return result;
        }

        public class RefreshResult<T, TContext>
        {
            private Dictionary<T, TContext> _toAdd;
            private List<T> _toDel;
            private Dictionary<T, TContext> _toUpdate;

            public RefreshResult() : this(-1)
            {
            }

            public RefreshResult(int capacity)
            {
                if (capacity <= 0)
                {
                    this._toDel = new List<T>();
                    this._toUpdate = new Dictionary<T, TContext>();
                    this._toAdd = new Dictionary<T, TContext>();
                }
                else
                {
                    this._toDel = new List<T>(capacity);
                    this._toUpdate = new Dictionary<T, TContext>(capacity);
                    this._toAdd = new Dictionary<T, TContext>(capacity);
                }
            }

            public Dictionary<T, TContext> ToAdd
            {
                get
                {
                    return this._toAdd;
                }
            }

            public List<T> ToDelete
            {
                get
                {
                    return this._toDel;
                }
            }

            public Dictionary<T, TContext> ToUpdate
            {
                get
                {
                    return this._toUpdate;
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -