using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Com.FirmLib.UI.Common
{
    /// <summary>
    /// 比较元素是否相等
    /// </summary>
    /// <typeparam name="E"></typeparam>
    public class TComparer<E> : IEqualityComparer<E>
    {
        private Func<E, E, bool> m_func;
        public TComparer()
        {
        }
        public TComparer(Func<E, E, bool> func)
        {
            m_func = func;
        }
        public bool Equals(E x, E y)
        {
            var tempFunc = m_func;
            if (m_func != null)
            {
                return m_func(x, y);
            }
            if (x == null && y == null)
                return true;
            if (x == null || y == null)
                return false;
            return x.Equals(y);
        }

        public int GetHashCode(E obj)
        {
            return 0;
        }
    }
}
