|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Collections.Generic; |
5 | 6 |
|
6 | 7 | namespace Microsoft.Build.Framework |
7 | 8 | { |
8 | 9 | /// <summary> |
9 | 10 | /// A readonly struct that represents task host parameters used to determine which host process to launch. |
10 | 11 | /// </summary> |
11 | | - public readonly struct TaskHostParameters |
| 12 | + public readonly struct TaskHostParameters : IEquatable<TaskHostParameters> |
12 | 13 | { |
13 | 14 | /// <summary> |
14 | 15 | /// A static empty instance to avoid allocations when default parameters are needed. |
@@ -72,6 +73,29 @@ internal TaskHostParameters( |
72 | 73 | /// </summary> |
73 | 74 | public bool? TaskHostFactoryExplicitlyRequested => _taskHostFactoryExplicitlyRequested; |
74 | 75 |
|
| 76 | + public override bool Equals(object? obj) => obj is TaskHostParameters other && Equals(other); |
| 77 | + |
| 78 | + public bool Equals(TaskHostParameters other) => |
| 79 | + StringComparer.OrdinalIgnoreCase.Equals(Runtime ?? string.Empty, other.Runtime ?? string.Empty) |
| 80 | + && StringComparer.OrdinalIgnoreCase.Equals(Architecture ?? string.Empty, other.Architecture ?? string.Empty) |
| 81 | + && TaskHostFactoryExplicitlyRequested == other.TaskHostFactoryExplicitlyRequested; |
| 82 | + |
| 83 | + public override int GetHashCode() |
| 84 | + { |
| 85 | + // Manual hash code implementation for compatibility with .NET Framework 4.7.2 |
| 86 | + var comparer = StringComparer.OrdinalIgnoreCase; |
| 87 | + |
| 88 | + unchecked |
| 89 | + { |
| 90 | + int hash = 17; |
| 91 | + hash = hash * 31 + comparer.GetHashCode(Runtime ?? string.Empty); |
| 92 | + hash = hash * 31 + comparer.GetHashCode(Architecture ?? string.Empty); |
| 93 | + hash = hash * 31 + (TaskHostFactoryExplicitlyRequested?.GetHashCode() ?? 0); |
| 94 | + |
| 95 | + return hash; |
| 96 | + } |
| 97 | + } |
| 98 | + |
75 | 99 | /// <summary> |
76 | 100 | /// Gets a value indicating whether returns true if parameters were unset. |
77 | 101 | /// </summary> |
@@ -134,7 +158,7 @@ internal TaskHostParameters WithTaskHostFactoryExplicitlyRequested(bool taskHost |
134 | 158 | /// <summary> |
135 | 159 | /// The method was added to sustain compatibility with ITaskFactory2 factoryIdentityParameters parameters dictionary. |
136 | 160 | /// </summary> |
137 | | - internal Dictionary<string, string> ToDictionary() => new(3) |
| 161 | + internal Dictionary<string, string> ToDictionary() => new(3, StringComparer.OrdinalIgnoreCase) |
138 | 162 | { |
139 | 163 | { nameof(Runtime), Runtime ?? string.Empty }, |
140 | 164 | { nameof(Architecture), Architecture ?? string.Empty }, |
|
0 commit comments