public static bool IsEqualTo <T>(this IReadOnlyList <T>?source1, IReadOnlyList <T>?source2, IEqualityComparer <T>?comparer = null) { if ((source1 == null) != (source2 == null)) { return(false); } if (source1 == null) { return(true); } if (source1 is T[] array1 && source2 is T[] array2) { return(array1.IsEqualTo(array2, comparer)); } if (source1.Count != source2 !.Count) { return(false); } var count = source1.Count; comparer = comparer.OrDefault(); for (int i = 0; i < count; i++) { if (!comparer.Equals(source1[i], source2[i])) { return(false); } } return(true); }
public static int GetCollectionHashCode <T>(this IReadOnlyCollection <T>?source, IEqualityComparer <T>?comparer = null) { if (source == null) { return(382720733); // Null hash code. I picked a large prime number } if (source is IReadOnlyList <T> array) { return(array.GetCollectionHashCode(comparer)); } return(ComputeEnumerableHashCode(source, comparer.OrDefault())); }
public Property(T?initialValue, Func <T?, T?, T?>?coerceValue = null, IEqualityComparer <T>?comparer = null) { this.Value = initialValue; this.coerceValue = coerceValue; stream = new BehaviorSubject <T>(CoerceValue(initialValue) !); ValueChanged = stream .DistinctUntilChanged(comparer.OrDefault()) .Select(_ => Unit.Default); disposables.Add(stream.Subscribe(value => Value = value)); disposables.Add(new Disposable(() => stream.OnCompleted())); }
public static bool IsEqualTo <T>(this IReadOnlyCollection <T>?source1, IReadOnlyCollection <T>?source2, IEqualityComparer <T>?comparer = null) { if ((source1 == null) != (source2 == null)) { return(false); } if (source1 == null) { return(true); } if (source1 is IReadOnlyList <T> list1 && source2 is IReadOnlyList <T> list2) { return(list1.IsEqualTo(list2, comparer)); } if (source1.Count != source2 !.Count) { return(false); } return(AreEqualEnumerables(source1, source2, comparer.OrDefault())); }
public PropertyEqualityComparer(Func <T, P> getProperty, IEqualityComparer <P>?propertyComparer = null) { this.getProperty = getProperty ?? throw new ArgumentNullException(nameof(getProperty)); this.propertyComparer = propertyComparer.OrDefault(); }
public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>( this IEnumerable <ValueTuple <TKey, TValue> > source, IEqualityComparer <TKey>?comparer = null) where TKey : notnull => source.ToDictionary(t => t.Item1, t => t.Item2, comparer.OrDefault());
public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>( this IEnumerable <KeyValuePair <TKey, TValue> > source, IEqualityComparer <TKey>?comparer = null) where TKey : notnull => new Dictionary <TKey, TValue>(source, comparer.OrDefault());