Exemplo n.º 1
0
        public static int GetHashCode <T>(this EqualityExtensionPoint <T> extensionPoint, IEnumerable <object> items)
        {
            var hashCode = typeof(T).GetHashCode();

            foreach (var item in items)
            {
                if (item != null)
                {
                    var newHashCode = 0;
                    // Will need to get the hashcode of all the items of the array
                    // and since a string is IEnumerable, we want to also exclude them from that logic
                    if (item is IEnumerable &&
                        !(item is string))
                    {
                        foreach (var hashItem in item as IEnumerable)
                        {
                            newHashCode ^= hashItem.GetHashCode();
                        }
                    }
                    else
                    {
                        newHashCode = item.GetHashCode();
                    }
                    hashCode = (int)(0xa5555529 * hashCode) + newHashCode;
                }
            }

            return(hashCode);
        }
Exemplo n.º 2
0
        public static bool Equal <T>(this EqualityExtensionPoint <T> x, T y)
        {
            var xValue = x.ExtendedValue;

            if (xValue == null)
            {
                return(y == null);
            }

            if (y == null)
            {
                return(false);
            }

            if (!(xValue is IEnumerable) && xValue.GetHashCode() != y.GetHashCode())
            {
                return(false);
            }

            if (Equals(x.ExtendedValue, y))
            {
                return(true);
            }

            if (x.ExtendedValue is IEnumerable xItems)
            {
                if (y is IEnumerable yItems)
                {
                    return(Equals(xItems, yItems, Predicates <object> .Equal));
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public static bool Equal <T>(this EqualityExtensionPoint <T> x, T y, Func <T, IEnumerable <object> > content,
                                     Func <object, object, bool> predicate)
        {
            var xItems = content(x.ExtendedValue);
            var yItems = content(y);

            return(Equals(xItems, yItems, predicate));
        }
Exemplo n.º 4
0
 public static bool Equal <T>(this EqualityExtensionPoint <T> x, object y, Func <T, IEnumerable <object> > content)
 {
     if (y is T)
     {
         return(Equal(x, (T)y, content));
     }
     return(false);
 }
Exemplo n.º 5
0
        public static int GetHashCode <T>(this EqualityExtensionPoint <T> extensionPoint, IEnumerable <object> items)
        {
            var hashCode = typeof(T).GetHashCode();

            foreach (var item in items)
            {
                if (item != null)
                {
                    hashCode = (int)(0xa5555529 * hashCode) + item.GetHashCode();
                }
            }

            return(hashCode);
        }
Exemplo n.º 6
0
        public static bool Equal <T>(this EqualityExtensionPoint <T> x, object y, Func <T, IEnumerable <object> > content)
        {
            var xValue = x.ExtendedValue;

            if (xValue == null || y == null)
            {
                return(false);
            }

            if (xValue.GetHashCode() != y.GetHashCode())
            {
                return(false);
            }

            if (y is T variable)
            {
                return(Equal(x, variable, content));
            }
            return(false);
        }
Exemplo n.º 7
0
        public static bool Equal <T>(this EqualityExtensionPoint <T> x, T y, Func <T, IEnumerable <object> > content,
                                     Func <object, object, bool> predicate)
        {
            var xValue = x.ExtendedValue;

            if (xValue == null || y == null)
            {
                return(false);
            }

            if (xValue.GetHashCode() != y.GetHashCode())
            {
                return(false);
            }

            var xItems = content(x.ExtendedValue);
            var yItems = content(y);

            return(Equals(xItems, yItems, predicate));
        }
Exemplo n.º 8
0
        public static bool Equal <T>(this EqualityExtensionPoint <T> x, T y)
        {
            if (Equals(x.ExtendedValue, y))
            {
                return(true);
            }

            var xItems = x.ExtendedValue as IEnumerable;

            if (xItems != null)
            {
                var yItems = y as IEnumerable;

                if (yItems != null)
                {
                    return(Equals(xItems, yItems, Predicates <object> .Equal));
                }
            }

            return(false);
        }
Exemplo n.º 9
0
 //TODO Useful?
 public static bool Equal <T>(this EqualityExtensionPoint <T> xItems, IEnumerable yItems)
     where T : IEnumerable
 {
     return(Equal(xItems, yItems, Predicates <object> .Equal));
 }
Exemplo n.º 10
0
 public static int GetHashCode <T>(this EqualityExtensionPoint <T> extensionPoint,
                                   Func <T, IEnumerable <object> > items)
 {
     return(GetHashCode(extensionPoint, items(extensionPoint.ExtendedValue)));
 }
Exemplo n.º 11
0
 public static IEqualityComparer <T> ToComparer <T>(this EqualityExtensionPoint <Func <T, T, bool> > extensionPoint)
 {
     return(new FuncEqualityComparer <T>(extensionPoint.ExtendedValue));
 }
Exemplo n.º 12
0
 public static bool Equal <T, TItem>(this EqualityExtensionPoint <T> xItems, IEnumerable <TItem> yItems,
                                     Func <TItem, TItem, bool> predicate)
     where T : IEnumerable <TItem>
 {
     return(xItems.ExtendedValue.SequenceEqual(yItems, predicate.Equality().ToComparer()));
 }
Exemplo n.º 13
0
 public static bool Equal <T, TItem>(this EqualityExtensionPoint <T> xItems, IEnumerable <TItem> yItems,
                                     IEqualityComparer <TItem> comparer)
     where T : IEnumerable <TItem>
 {
     return(Equal(xItems, yItems, comparer.Equals));
 }
Exemplo n.º 14
0
 public static bool Equal <T, TItem>(this EqualityExtensionPoint <T> xItems, IEnumerable <TItem> yItems)
     where T : IEnumerable <TItem>
 {
     return(Equal(xItems, yItems, Predicates <TItem> .Equal));
 }
Exemplo n.º 15
0
 public static bool Equal <T>(this EqualityExtensionPoint <T> xItems, IEnumerable yItems,
                              Func <object, object, bool> predicate)
     where T : IEnumerable
 {
     return(Equals(xItems.ExtendedValue, yItems, predicate));
 }
Exemplo n.º 16
0
 public static bool Equal <T>(this EqualityExtensionPoint <T> x, T y, Func <T, IEnumerable <object> > content,
                              IEqualityComparer comparer)
 {
     return(Equal(x, y, content, comparer.Equals));
 }
Exemplo n.º 17
0
 public static bool Equal <T>(this EqualityExtensionPoint <T> x, T y, Func <T, IEnumerable <object> > content)
 {
     return(Equal(x, y, content, Predicates <object> .Equal));
 }