-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make load contexts dependent on weaver paths
- Loading branch information
1 parent
4efd176
commit 21bcb7e
Showing
3 changed files
with
62 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Fody; | ||
|
||
public sealed class AssemblyPathSet : IEquatable<AssemblyPathSet> | ||
{ | ||
readonly HashSet<string> assemblyPaths; | ||
readonly int hashCode; | ||
|
||
public IReadOnlyCollection<string> AssemblyPaths => assemblyPaths; | ||
|
||
public AssemblyPathSet(IEnumerable<string> paths) | ||
{ | ||
var stringComparer = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; | ||
|
||
assemblyPaths = new(paths, stringComparer); | ||
hashCode = 0; | ||
|
||
foreach (var path in assemblyPaths.OrderBy(i => i, stringComparer)) | ||
{ | ||
hashCode = (hashCode * 397) ^ path.GetHashCode(); | ||
} | ||
} | ||
|
||
public bool Equals(AssemblyPathSet? other) => | ||
other is not null && assemblyPaths.SetEquals(other.assemblyPaths); | ||
|
||
public override bool Equals(object? obj) => | ||
obj is AssemblyPathSet other && Equals(other); | ||
|
||
public override int GetHashCode() => | ||
hashCode; | ||
} |
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
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,23 @@ | ||
namespace Tests.Fody; | ||
|
||
public class AssemblyPathSetTests | ||
{ | ||
[Fact] | ||
public void ShouldDetectEquality() | ||
{ | ||
var a = new AssemblyPathSet(["foo", "bar"]); | ||
var b = new AssemblyPathSet(["bar", "foo", "bar"]); | ||
|
||
Assert.Equal(a, b); | ||
Assert.Equal(a.GetHashCode(), b.GetHashCode()); | ||
} | ||
|
||
[Fact] | ||
public void ShouldDetectInequality() | ||
{ | ||
var a = new AssemblyPathSet(["foo", "bar"]); | ||
var b = new AssemblyPathSet(["foo", "baz"]); | ||
|
||
Assert.NotEqual(a, b); | ||
} | ||
} |