public void Equals_should_apply_provided_comparer_function() { var dynamicComparer = new DynamicEqualityComparer<string>((a, b) => a.Length > b.Length); Assert.True(dynamicComparer.Equals("a", "")); Assert.False(dynamicComparer.Equals("foo", "bar")); }
public void GetHashCode_is_no_op() { var dynamicComparer = new DynamicEqualityComparer<string>((_, __) => false); Assert.Equal(0, dynamicComparer.GetHashCode("a")); Assert.Equal(0, dynamicComparer.GetHashCode("b")); }
/// <summary> /// Retrieves a collection that represents all the properties defined on a specified <paramref name="type"/> except those defined on <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The type to exclude properties on <paramref name="type"/>.</typeparam> /// <param name="type">The type that contains the properties to include except those defined on <typeparamref name="T"/>.</param> /// <returns>A collection of properties for the specified <paramref name="type"/> except those defined on <typeparamref name="T"/>.</returns> public static IEnumerable <PropertyInfo> GetRuntimePropertiesExceptOf <T>(this Type type) { var baseProperties = typeof(T).GetRuntimeProperties(); var typeProperties = type.GetRuntimeProperties(); return(typeProperties.Except(baseProperties, DynamicEqualityComparer.Create <PropertyInfo>(pi => $"{pi.Name}-{pi.PropertyType.Name}".GetHashCode32(), (x, y) => x.Name == y.Name && x.PropertyType.Name == y.PropertyType.Name))); }
public MainExecutionGroup() { var importersPath = Path.Combine(ApplicationInfo.ApplicationPath.FullName, "Importers"); if (!Directory.Exists(importersPath)) { Directory.CreateDirectory(importersPath); } Assemblies.LoadAssembly(new DirectoryInfo(importersPath)); this.importers = Factory.CreateMany <IFileImporter>(); this.hostFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "Drivers", "etc", "hosts"); this.equalityComparer = new DynamicEqualityComparer <HostFileLine>( (a, b) => string.Equals(a.HostName, b.HostName, StringComparison.InvariantCultureIgnoreCase), x => x.HostName.GetHashCode()); }
void RaisePropertyChangedEvent <TValue>(IClampedPropertyT <TValue> prop, TValue v, TValue min, TValue max, Action action, IEnumerable <EventData <PropertyChangedEventArgs> > expected) where TValue : IComparable <TValue> { prop.Minimum = min; prop.Maximum = max; prop.Value = v; if (expected.Count() > 0) { Test.If.Action.RaisesPropertyChangedEvent(action, prop, out EventDataCollection <PropertyChangedEventArgs> eventDatas); Test.If.Enumerable.Matches(eventDatas, expected, DynamicEqualityComparer.FromDelegate <EventData <PropertyChangedEventArgs> >( (x, y) => ReferenceEquals(x.Sender, y.Sender) && x.EventArgs.PropertyName == y.EventArgs.PropertyName, (obj) => obj.GetHashCode())); } else { Test.IfNot.Action.RaisesPropertyChangedEvent(action, prop, out EventDataCollection <PropertyChangedEventArgs> _); } }
public static IEnumerable <T> Distinct <T>(this IEnumerable <T> source, Func <T, T, bool> compareFunction, Func <T, int> hashFunction = null) { var ecomparer = new DynamicEqualityComparer <T>(compareFunction, hashFunction); return(source.Distinct(ecomparer)); }
/// <summary> /// Determines whether the <see cref="IndexProvisionCollection" /> contains a specific value. /// </summary> /// <param name="provision">The <see cref="IndexProvision"/> to locate in the <see cref="IndexProvisionCollection" />.</param> /// <returns><c>true</c> if <paramref name="provision" /> is found in the <see cref="IndexProvisionCollection" />; otherwise, <c>false</c>.</returns> public override bool Contains(IndexProvision provision) { return(Contains(provision, DynamicEqualityComparer.Create <IndexProvision>(ix => ix.IndexName.GetHashCode(), (i1, i2) => i1.IndexName.GetHashCode() == i2.IndexName.GetHashCode()))); }
protected MonitorBase(DynamicEqualityComparer <T> comparer, BoolAction <T> isblacklisted) { this.comparer = comparer; this.isblacklisted = isblacklisted; }
protected MonitorBase() { comparer = new DynamicEqualityComparer <T>(((x, y) => x?.Equals(y) == true), x => x?.GetHashCode() ?? 0); }
/// <summary> /// Determines whether the <see cref="SecondaryIndexCollection{T}" /> contains a specific value. /// </summary> /// <param name="index">The <see cref="SecondaryIndex"/> to locate in the <see cref="SecondaryIndexCollection{T}" />.</param> /// <returns><c>true</c> if <paramref name="index" /> is found in the <see cref="SecondaryIndexCollection{T}" />; otherwise, <c>false</c>.</returns> public override bool Contains(T index) { return(Contains(index, DynamicEqualityComparer.Create <SecondaryIndex>(ix => ix.IndexName.GetHashCode(), (i1, i2) => i1.IndexName.GetHashCode() == i2.IndexName.GetHashCode()))); }
protected MonitorSingleBase() { comparer = new DynamicEqualityComparer <T>(((x, y) => x.Equals(y)), x => x.GetHashCode()); }