示例#1
0
        public override bool Equals(object obj)
        {
            if (!this.HasValue)
            {
                if (obj is Key <TValue> )
                {
                    return(!((Key <TValue>)obj).HasValue);
                }

                return(obj == null);
            }

            TValue otherValue;

            if (obj is Key <TValue> )
            {
                otherValue = ((Key <TValue>)obj).Value;
            }
            else
            {
                otherValue = (TValue)obj;
            }

            var comparer = ComparerCache.Get <TValue>();

            if (comparer != null)
            {
                return(comparer.Equals(Value, otherValue));
            }

            return(object.Equals(Value, otherValue));
        }
示例#2
0
        public override int GetHashCode()
        {
            if (!this.HasValue)
            {
                return(0);
            }

            var comparer = ComparerCache.Get <TValue>();

            if (comparer != null)
            {
                return(comparer.GetHashCode(Value));
            }

            return(this.Value.GetHashCode());
        }