-
-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1269 from ltrzesniewski/change-load-contexts
Base load contexts on weaver paths
- Loading branch information
Showing
4 changed files
with
76 additions
and
13 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
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); | ||
} | ||
} |