-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some additional document source comparison helpers
- Loading branch information
1 parent
1e6226f
commit c53990d
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/core/Statiq.Common/Documents/DocumentSourceComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Statiq.Common | ||
{ | ||
/// <summary> | ||
/// A simple <see cref="IEqualityComparer{IDocument}"/> that compares documents by <see cref="IDocument.Source"/>. | ||
/// </summary> | ||
public class DocumentSourceComparer : IEqualityComparer<IDocument> | ||
{ | ||
public static DocumentSourceComparer Instance { get; } = new DocumentSourceComparer(); | ||
|
||
public bool Equals(IDocument x, IDocument y) => | ||
(x is null && y is null) || (x is object && y is object && x.Source.Equals(y.Source)); | ||
|
||
public int GetHashCode(IDocument obj) => obj?.Source.GetHashCode() ?? 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters