Skip to content

RuntimeHandles should implement IEquatable #62944

@MichalStrehovsky

Description

@MichalStrehovsky

Background and motivation

RuntimeTypeHandle is often used as a key in a dictionary. See hits on github: https://grep.app/search?q=dictionary%3Cruntimetypehandle. The search results include high profile libraries such a CsWinRt.

The runtime handles already implement strongly typed Equals(XXXHandle other) methods, but without the interfaces, dictionaries are going to use the Equals(object other) implementations instead, needlessly boxing the argument, unless a custom comparer is provided (it isn't in the above search results...).

API Proposal

namespace System
{
    public struct RuntimeTypeHandle : IEquatable<RuntimeTypeHandle>
    {
        // bool Equals(RuntimeTypeHandle) already exists
    }

    public struct RuntimeMethodHandle : IEquatable<RuntimeMethodHandle>
    {
        // bool Equals(RuntimeMehtodHandle) already exists
    }

    public struct RuntimeFieldHandle : IEquatable<RuntimeFieldHandle>
    {
        // bool Equals(RuntimeFieldHandle) already exists
    }
}

API Usage

No boxing.

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Runtimecode-analyzerMarks an issue that suggests a Roslyn analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions