-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Make DependencyModel.Dependency readonly and implement IEquatable<> #56082
Comments
Tagging subscribers to this area: @eerhardt Issue DetailsBackground and motivationThe current implementation looks like namespace Microsoft.Extensions.DependencyModel
{
public struct Dependency
{
// for readonly proposal
public string Name { get; }
public string Version { get; }
// for IEquatable<> proposal
public bool Equals(Dependency other);
public override bool Equals(object obj); // common pattern with is T t && Equals(t)
public override int GetHashCode();
}
} So, all required members for IEquatable<> exist and properties aren't settable API Proposalnamespace Microsoft.Extensions.DependencyModel
{
- public struct Dependency {}
+ public readonly struct Dependency : IEquatable<Dependency> {}
} The main point here is that nothing will be changed in the implementation as it already satisfied for these changes API UsageThere are already some usages in HashSet<> where new runtime/src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextWriter.cs Line 266 in 57bfe47
and some in dotnet/sdk Also RisksNone?
|
Thanks for the suggestion. Seems reasonable to me. |
Looks good as proposed. namespace Microsoft.Extensions.DependencyModel
{
- public struct Dependency {}
+ public readonly struct Dependency : IEquatable<Dependency> {}
} |
@bartonjs, @terrajobst, we explicitly disable CA1066 because we have a bunch of types that don't do this "correctly": runtime/eng/CodeAnalysis.src.globalconfig Lines 154 to 155 in 03601a7
Should we holistically make a pass through all of them rather than continuing with these one-offs? |
Hmm, maybe instead of disabling that rule we should just pragma suppress the files that host these types? |
We could... for reference, here are the resulting warnings if it's enabled currently: 68 Warning(s)
|
68 types doesn't seem too bad. But yeah. |
Background and motivation
Similar to #31996 and #2127
The current implementation looks like
So, all required members for IEquatable<> exist and properties aren't settable
API Proposal
The main point here is that nothing will be changed in the implementation as it already satisfied for these changes
API Usage
There are already some usages in HashSet<> where new
EqualityComparer
will be usedruntime/src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextWriter.cs
Line 266 in 57bfe47
and some in dotnet/sdk
Also
Dependency
is public, so it might be useful for someone else 😄Risks
None?
The text was updated successfully, but these errors were encountered: