Skip to content
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

Add a PrimaryAttribute type #28200

Open
TylerBrinkley opened this issue Dec 13, 2018 · 2 comments
Open

Add a PrimaryAttribute type #28200

TylerBrinkley opened this issue Dec 13, 2018 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime
Milestone

Comments

@TylerBrinkley
Copy link
Contributor

Split from #20008

For the Enum method GetName when there are multiple enum members with the same value the name it returns is undefined. I propose adding a PrimaryAttribute to be applied to enum members where there is ambiguity which will ensure its name is returned.

Proposed API

namespace System.ComponentModel {
    public sealed class PrimaryAttribute : Attribute {
        public PrimaryAttribute();
    }
}

API Details

  • The PrimaryAttribute is used to specify what enum member to retrieve when there are multiple enum members with the same value. It could be used for more than just enum members for cases in code where there is ambiguity.
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@ericstj ericstj modified the milestones: 5.0.0, Future Jul 1, 2020
@ericstj ericstj removed the untriaged New issue has not been triaged by the area owner label Jul 1, 2020
@ericstj
Copy link
Member

ericstj commented Jul 1, 2020

Though the API as proposed places this in System.ComponentModel, it would need to be understood by Enum.GetName which is actually CoreLib / System.Runtime.

FWIW it isn't "undefined" it's just not entirely predictable.

@TylerBrinkley
Copy link
Contributor Author

Yes, it would need to be defined in corelib to be understood by System.Enum.

It could additionally be used for specifying the constructor to invoke in deserialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime
Projects
None yet
Development

No branches or pull requests

4 participants