Skip to content

[API Proposal]: Make DependencyModel.Dependency readonly and implement IEquatable<> #56082

@hrrrrustic

Description

@hrrrrustic

Background and motivation

Similar to #31996 and #2127

The 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 Proposal

namespace 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 Usage

There are already some usages in HashSet<> where new EqualityComparer will be used

and some in dotnet/sdk

Also Dependency is public, so it might be useful for someone else 😄

Risks

None?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions