├── src
├── ClickToBuild.bat
├── .nuget
│ ├── NuGet.Config
│ └── NuGet.targets
├── EqualityComparer
│ ├── Settings.StyleCop
│ ├── DateComparisonType.cs
│ ├── EqualityComparer.nuspec
│ ├── DateTimeExtensions.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Reflection
│ │ ├── EventInfoComparer.cs
│ │ ├── PropertyInfoComparer.cs
│ │ ├── ParameterInfoComparer.cs
│ │ ├── FieldInfoComparer.cs
│ │ ├── MethodInfoComparer.cs
│ │ ├── ConstructorInfoComparer.cs
│ │ ├── MemberInfoComparer.cs
│ │ └── TypeExtensions.cs
│ ├── DateComparer.cs
│ ├── EqualityComparer.csproj
│ ├── GenericEqualityComparer.cs
│ └── MemberComparer.cs
├── EqualityComparer.Tests
│ ├── Settings.StyleCop
│ ├── packages.config
│ ├── Reflection
│ │ ├── MemberInfoComparerTest.cs
│ │ ├── FieldInfoComparerTest.cs
│ │ ├── ConstructorInfoComparerTest.cs
│ │ ├── EventInfoComparerTest.cs
│ │ ├── ParameterInfoComparerTest.cs
│ │ ├── MethodInfoComparerTest.cs
│ │ └── TypeExtensionsTest.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── DateComparerTest.cs
│ ├── DateTimeExtensionsTest.cs
│ ├── GenericEqualityComparerTest.cs
│ ├── EqualityComparer.Tests.csproj
│ └── MemberComparerTest.cs
├── gendarme.ignore
├── NuGetPack.ps1
└── EqualityComparer.sln
├── logo-128.png
├── .editorconfig
├── LICENSE.md
├── .hgignore
├── .gitignore
└── README.md
/src/ClickToBuild.bat:
--------------------------------------------------------------------------------
1 | PowerShell -Command ".\Build\build.ps1 BuildAll"
2 | pause
--------------------------------------------------------------------------------
/logo-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Iristyle/EqualityComparer/HEAD/logo-128.png
--------------------------------------------------------------------------------
/src/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = crlf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
--------------------------------------------------------------------------------
/src/EqualityComparer/Settings.StyleCop:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ..\Build\Settings.StyleCop
5 | Linked
6 |
7 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/Settings.StyleCop:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ..\Build\Settings.Test.StyleCop
5 | Linked
6 |
7 |
--------------------------------------------------------------------------------
/src/EqualityComparer/DateComparisonType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EqualityComparer
4 | {
5 | /// Defines how to compare dates when using DateComaper{T}.
6 | /// ebrown, 6/18/2011.
7 | public enum DateComparisonType
8 | {
9 | /// An exact comparison by ticks.
10 | Exact,
11 | /// A comparison truncated / always rounded down to the nearest second, which can be useful with data stores that do not roundtrip dates properly.
12 | TruncatedToSecond
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/gendarme.ignore:
--------------------------------------------------------------------------------
1 | # see https://github.com/mono/mono-tools/blob/master/gendarme/mono-options.ignore for complete example
2 | # implemented in https://github.com/mono/mono-tools/blob/master/gendarme/console/IgnoreFileList.cs
3 | # single rule must be followed by one or more targets
4 |
5 | # comment
6 | # R: Rule
7 | # M: Method
8 | # T: Type (no spaces allowed)
9 | # A: Assembly - we support Name, FullName and *
10 | # N: namespace - special case (no need to resolve)
11 | # @: include file
12 | # for instance
13 | # R: Gendarme.Rules.Design.Generic.PreferGenericsOverRefObjectRule
14 | # A: *
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/Reflection/MemberInfoComparerTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Xunit;
4 |
5 | namespace EqualityComparer.Reflection.Tests
6 | {
7 | public class MemberInfoComparerTest
8 | {
9 | class TypeA
10 | {
11 | public int Test { get; set; }
12 | }
13 |
14 | class TypeB
15 | {
16 | public int Test { get; set; }
17 | }
18 |
19 | [Fact]
20 | public void Equals_True_ForIdenticalTypes()
21 | {
22 | Assert.True(typeof(TypeA).GetMembers().SequenceEqual(typeof(TypeB).GetMembers(), MemberInfoComparer.Default));
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/Reflection/FieldInfoComparerTest.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 | using System.Linq;
3 | using Xunit;
4 |
5 | namespace EqualityComparer.Reflection.Tests
6 | {
7 | public class FieldInfoComparerTest
8 | {
9 | class TypeA
10 | {
11 | [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Test Code")]
12 | public int Test = 0;
13 | }
14 |
15 | class TypeB
16 | {
17 | [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Test Code")]
18 | public int Test = 0;
19 | }
20 |
21 | [Fact]
22 | public void Equals_True_OnTypesOfSameSignature()
23 | {
24 | Assert.True(typeof(TypeA).GetFields().SequenceEqual(typeof(TypeB).GetFields(), FieldInfoComparer.Default));
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/Reflection/ConstructorInfoComparerTest.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 | using System.Linq;
3 | using Xunit;
4 |
5 | namespace EqualityComparer.Reflection.Tests
6 | {
7 | public class ConstructorInfoComparerTest
8 | {
9 | class TypeA
10 | {
11 | [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "Test Code")]
12 | public TypeA(int test) { }
13 | }
14 |
15 | class TypeB
16 | {
17 | [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "Test Code")]
18 | public TypeB(int test) { }
19 | }
20 |
21 | [Fact]
22 | public void Equals_True_OnTypesOfSameSignature()
23 | {
24 | Assert.True(typeof(TypeA).GetConstructors().SequenceEqual(typeof(TypeB).GetConstructors(), ConstructorInfoComparer.Default));
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/NuGetPack.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
3 | [string]
4 | $apiKey
5 | )
6 |
7 | function Pack-And-Push
8 | {
9 | $thisName = $MyInvocation.MyCommand.Name
10 | $currentDirectory = [IO.Path]::GetDirectoryName((Get-Content function:$thisName).File)
11 | Write-Host "Running against $currentDirectory"
12 | $nuget = Get-ChildItem -Path $currentDirectory -Include 'nuget.exe' -Recurse |
13 | Select -ExpandProperty FullName -First 1
14 |
15 | Get-ChildItem -Path $currentDirectory -Include *.nuspec -Recurse |
16 | % { Join-Path ([IO.Path]::GetDirectoryName($_)) ([IO.Path]::GetFileNameWithoutExtension($_) + '.csproj') } |
17 | ? { Test-Path $_ } |
18 | % { Start-Process $nuget -ArgumentList "pack $_ -Build -Prop Configuration=Release -Exclude '**\*.CodeAnalysisLog.xml'" -NoNewWindow -Wait }
19 |
20 | Get-ChildItem *.nupkg | % { &$nuget push $_ $apiKey }
21 | }
22 |
23 | del *.nupkg
24 | Pack-And-Push
25 | del *.nupkg
26 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (C) 2011 East Point Systems, Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 | of the Software, and to permit persons to whom the Software is furnished to do
8 | so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
--------------------------------------------------------------------------------
/src/EqualityComparer/EqualityComparer.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | $title$
7 | Ethan Brown
8 | $author$
9 | Opensource .NET helpers for easily comparing objects by their property / member values
10 | false
11 | $description$
12 | Initial release
13 | https://github.com/EastPoint/EqualityComparer
14 | https://github.com/EastPoint/EqualityComparer/blob/master/LICENSE.md
15 | https://github.com/EastPoint/EqualityComparer/raw/master/logo-128.png
16 | equality comparer expression reflection
17 | en-US
18 | East Point Systems 2012 and contributors
19 |
20 |
--------------------------------------------------------------------------------
/.hgignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 |
3 | *.*scc
4 | *.FileListAbsolute.txt
5 | *.aps
6 | *.bak
7 | *.[Cc]ache
8 | *.clw
9 | *.eto
10 | *.exe
11 | *.fb6lck
12 | *.fbl6
13 | *.fbpInf
14 | *.ilk
15 | *.lib
16 | *.log
17 | *.ncb
18 | *.nlb
19 | *.[Oo]bj
20 | *.patch
21 | *.pch
22 | *.pdb
23 | *.plg
24 | ipch/
25 | *.[Pp]ublish.xml
26 | *.rdl.data
27 | *.sbr
28 | *.sdf
29 | *.opensdf
30 | *.unsuccessfulbuild
31 | *.opt
32 | *.scc
33 | *.sig
34 | *.sqlsuo
35 | *.suo
36 | *.svclog
37 | *.tlb
38 | *.tlh
39 | *.tli
40 | *.trends
41 | *.tmp
42 | *.user
43 | *.vshost.*
44 | *.vsmdi
45 | *DXCore.Solution
46 | *_i.c
47 | *_p.c
48 | Ankh.Load
49 | Ankh.NoLoad
50 | Backup*
51 | CVS/
52 | .svn
53 | [Pp]recompiled[Ww]eb/
54 | UpgradeLog*.*
55 | [Bb]uildArtifacts/
56 | [Bb]in/
57 | [Dd]ebug/
58 | [Oo]bj/
59 | [Rr]elease/
60 | [Ss]andcastle/[Dd]ata
61 | [Tt]humbs.db
62 | _[Uu]pgradeReport_[Ff]iles
63 | _[Rr]e[Ss]harper*/
64 | *.resharper
65 | [Tt]est[Rr]esult*
66 | hgignore[.-]*
67 | ignore[.-]*
68 | svnignore[.-]*
69 | lint.db
70 | .DS_Store
71 | [Cc]lientBin/
72 | [Ii]ndex.dat
73 | [Ss]torage.dat
74 | *.sln.docstates
75 | ~$*
76 | packages/
77 | *.orig
78 | *.dbmdl
79 | *.dbproj.schemaview
80 | *.xap
--------------------------------------------------------------------------------
/src/EqualityComparer/DateTimeExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EqualityComparer
4 | {
5 | /// Date time extensions.
6 | /// 7/19/2011.
7 | public static class DateTimeExtensions
8 | {
9 | /// Truncates DateTime to second, so that JSON values with DateTimes can be roundtripped / compared properly.
10 | /// 7/19/2011.
11 | /// Original DateTime value.
12 | /// A new DateTime value truncated to the nearest second.
13 | public static DateTime TruncateToSecond(this DateTime value)
14 | {
15 | return new DateTime((value.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond);
16 | }
17 |
18 | /// A DateTime extension method that rounds DateTimes to the nearest second.
19 | /// 7/19/2011.
20 | /// Original DateTime value.
21 | /// A new DateTime value rounded and truncated to the nearest second.
22 | public static DateTime RoundToNearestSecond(this DateTime value)
23 | {
24 | if (value.Millisecond >= 500)
25 | //account for tiny discrepancies with ms and ticks
26 | value = value.AddMilliseconds(502);
27 |
28 | return TruncateToSecond(value);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.CompilerServices;
5 | using System.Runtime.InteropServices;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("EqualityComparer.Tests")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyProduct("EqualityComparer.Tests")]
13 | [assembly: AssemblyCulture("")]
14 | [assembly: AssemblyCompany("East Point Systems, Inc. http://www.eastpointsystems.com/")]
15 | [assembly: AssemblyCopyright("Copyright © 2012 East Point Systems, Inc.")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyConfiguration("")]
18 | [assembly: AssemblyVersion("0.1.2.0")]
19 | [assembly: AssemblyFileVersion("0.1.2.0")]
20 | [assembly: AssemblyInformationalVersion("0.1.2.0")]
21 | [assembly: CLSCompliant(true)]
22 | [assembly: NeutralResourcesLanguage("en")]
23 |
24 | // Setting ComVisible to false makes the types in this assembly not visible
25 | // to COM components. If you need to access a type in this assembly from
26 | // COM, set the ComVisible attribute to true on that type.
27 | [assembly: ComVisible(false)]
28 |
29 | // The following GUID is for the ID of the typelib if this project is exposed to COM
30 | [assembly: Guid("9cbd6f87-b7b8-448b-b197-ba9f33605f3b")]
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 |
3 | #OS junk files
4 | [Tt]humbs.db
5 | *.DS_Store
6 | [Ii]ndex.dat
7 | [Ss]torage.dat
8 |
9 | #Visual Studio files
10 | *.[Oo]bj
11 | *.user
12 | *.aps
13 | *.pch
14 | *.pdb
15 | *.scc
16 | *.*scc
17 | *_i.c
18 | *_p.c
19 | *.ncb
20 | *.suo
21 | *.tlb
22 | *.tlh
23 | *.tli
24 | *.bak
25 | *.[Cc]ache
26 | *.ilk
27 | *.log
28 | *.lib
29 | *.sbr
30 | *.sdf
31 | *.opensdf
32 | *.unsuccessfulbuild
33 | *.opt
34 | *.plg
35 | ipch/
36 | obj/
37 | [Bb]in
38 | [Dd]ebug*/
39 | [Rr]elease*/
40 | Ankh.Load
41 | Ankh.NoLoad
42 | *.vshost.*
43 | *.FileListAbsolute.txt
44 | *.clw
45 | *.eto
46 | *.vsmdi
47 | *.dbmdl
48 | *.dbproj.schemaview
49 |
50 | #ASP.NET
51 | [Pp]recompiled[Ww]eb/
52 | UpgradeLog*.*
53 | _[Uu]pgradeReport_[Ff]iles
54 | *.[Pp]ublish.xml
55 |
56 | #Silverlight
57 | [Cc]lientBin/
58 | *.xap
59 |
60 | #WCF
61 | *.svclog
62 |
63 | #SSRS and SSMS
64 | *.rdl.data
65 | *.sqlsuo
66 |
67 | #Tooling
68 | _[Rr]e[Ss]harper*/
69 | *.resharper
70 | [Tt]est[Rr]esult*
71 | *DXCore.Solution
72 | *.sln.docstates
73 | *.fbpInf
74 | lint.db
75 |
76 | #Build Scripts
77 | [Bb]uildArtifacts/
78 | [Ss]andcastle/[Dd]ata
79 | *.trends
80 |
81 | #Project files
82 | [Bb]uild/
83 |
84 | #TFS Files
85 | *.nlb
86 |
87 | #Other Source Control
88 | hgignore[.-]*
89 | ignore[.-]*
90 | svnignore[.-]*
91 | *.orig
92 |
93 | #CVS / Subversion files
94 | CVS/
95 | .svn
96 |
97 | # Office Temp Files
98 | ~$*
99 |
100 | #NuGet
101 | [Pp]ackages/
102 | *.nupkg
103 |
104 | #Miscellaneous Files
105 | *.exe
106 | *.fb6lck
107 | *.fbl6
108 | *.patch
109 | *.sig
110 | *.tmp
111 | Backup*
112 |
113 | #Test related files
114 | *.ncrunchsolution
115 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/Reflection/EventInfoComparerTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Reflection;
4 | using Xunit;
5 |
6 | namespace EqualityComparer.Reflection.Tests
7 | {
8 | public class EventInfoComparerTest
9 | {
10 | class A
11 | {
12 | public event EventHandler Test;
13 | public event EventHandler Test2;
14 |
15 | //placeholders to remove compiler warnings
16 | private void CallTest() { var TestCopy = Test; if (null != TestCopy) { TestCopy(this, EventArgs.Empty); } }
17 | private void CallTest2() { var TestCopy2 = Test2; if (null != TestCopy2) { TestCopy2(this, new UnhandledExceptionEventArgs(new DivideByZeroException(), false)); } }
18 | }
19 |
20 | class B
21 | {
22 | public event EventHandler Test;
23 | public event EventHandler Test2;
24 |
25 | //placeholders to remove compiler warnings
26 | private void CallTest() { var TestCopy = Test; if (null != TestCopy) { TestCopy(this, EventArgs.Empty); } }
27 | private void CallTest2() { var TestCopy2 = Test2; if (null != TestCopy2) { TestCopy2(this, new UnhandledExceptionEventArgs(new DivideByZeroException(), false)); } }
28 | }
29 |
30 | [Fact]
31 | public void Equals_True_OnTypesOfSameSignature()
32 | {
33 | Assert.True(typeof(A).GetEvents().SequenceEqual(typeof(B).GetEvents(), EventInfoComparer.Default));
34 | }
35 |
36 | [Fact]
37 | public void Equals_False_OnNullFirstParameter()
38 | {
39 | Assert.False(EventInfoComparer.Default.Equals(null, (EventInfo)typeof(A).GetMember("Test")[0]));
40 | }
41 |
42 | [Fact]
43 | public void Equals_False_OnNullSecondParameter()
44 | {
45 | Assert.False(EventInfoComparer.Default.Equals((EventInfo)typeof(A).GetMember("Test")[0], null));
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/EqualityComparer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics.CodeAnalysis;
3 | using System.Reflection;
4 | using System.Resources;
5 | using System.Runtime.InteropServices;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("EqualityComparer")]
11 | [assembly: AssemblyDescription("A set of Expression tree based object instance comparers")]
12 | [assembly: AssemblyProduct("EqualityComparer")]
13 | [assembly: AssemblyCulture("")]
14 | [assembly: AssemblyCompany("East Point Systems, Inc. http://www.eastpointsystems.com/")]
15 | [assembly: AssemblyCopyright("Copyright © 2012 East Point Systems, Inc.")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyConfiguration("")]
18 | [assembly: AssemblyVersion("0.1.2.0")]
19 | [assembly: AssemblyFileVersion("0.1.2.0")]
20 | [assembly: AssemblyInformationalVersion("0.1.2.0")]
21 | [assembly: CLSCompliant(true)]
22 | [assembly: NeutralResourcesLanguage("en")]
23 |
24 | // Setting ComVisible to false makes the types in this assembly not visible
25 | // to COM components. If you need to access a type in this assembly from
26 | // COM, set the ComVisible attribute to true on that type.
27 | [assembly: ComVisible(false)]
28 |
29 | // The following GUID is for the ID of the typelib if this project is exposed to COM
30 | [assembly: Guid("34a5780f-8fc9-49d4-90c4-67d866e3c693")]
31 |
32 | [assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Target = "EqualityComparer", Scope = "namespace", Justification = "Simple library!")]
33 | [assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Target = "EqualityComparer.Reflection", Scope = "namespace", Justification = "Helpers mirror .NET framework type layout")]
34 |
--------------------------------------------------------------------------------
/src/EqualityComparer/Reflection/EventInfoComparer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Reflection;
5 |
6 | namespace EqualityComparer.Reflection
7 | {
8 | /// Event information comparer.
9 | /// ebrown, 2/3/2011.
10 | public class EventInfoComparer : EqualityComparer
11 | {
12 | private static Lazy _default = new Lazy(() => new EventInfoComparer());
13 |
14 | /// Gets the default EventInfoComparer instance, rather than continually constructing new instances.
15 | /// The default.
16 | public static new EventInfoComparer Default { get { return _default.Value; } }
17 |
18 | /// Tests if two EventInfo objects are considered equal by our definition -- same Name, EventHandlerType, IsMulticast, Attributes.
19 | /// ebrown, 2/3/2011.
20 | /// EventInfo instance to be compared.
21 | /// EventInfo instance to be compared.
22 | /// true if the objects are considered equal, false if they are not.
23 | public override bool Equals(EventInfo x, EventInfo y)
24 | {
25 | if (x == y) { return true; }
26 | if ((x == null) || (y == null)) { return false; }
27 |
28 | return (x.Name == y.Name &&
29 | x.EventHandlerType == y.EventHandlerType &&
30 | x.IsMulticast == y.IsMulticast &&
31 | x.Attributes == y.Attributes);
32 | }
33 |
34 | /// Calculates the hash code for this object.
35 | /// ebrown, 2/3/2011.
36 | /// The object.
37 | /// The hash code for this object.
38 | public override int GetHashCode(EventInfo obj)
39 | {
40 | if (null == obj) { return 0; }
41 | return string.Format(CultureInfo.CurrentCulture, "Member:{0}Name:{1}EventHandlerType:{2}", obj.MemberType, obj.Name, obj.EventHandlerType).GetHashCode();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/EqualityComparer.Tests/DateComparerTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Xunit;
5 | using Xunit.Extensions;
6 |
7 | namespace EqualityComparer.Tests
8 | {
9 | public class DateComparerTest
10 | {
11 | private static DateTime wellKnownDate = new DateTime(2011, 6, 20, 13, 30, 1, 200);
12 |
13 | public static IEnumerable