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

[Feature Request] nameof(X)u8 : Generating UTF-8 byte sequences using nameof() #74979

Closed
xin9le opened this issue Sep 3, 2024 · 2 comments
Closed
Labels
Area-Language Design Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@xin9le
Copy link

xin9le commented Sep 3, 2024

Background and Motivation

UTF-8 literals were introduced in C# 11, which has been extremely beneficial for developers performing optimizations using UTF-8 byte sequences. However, at present, it is not possible to apply u8 to nameof(). This proposal aims to simplify the generation of UTF-8 byte sequences in a manner that follows name changes. Additionally, it will bridge the asymmetry gap between the generation of regular strings and UTF-8 byte sequences.

// string
string t1 = "CSharp";
string t2 = nameof(Language.CSharp);

// UTF-8 string
ReadOnlySpan<byte> = "CSharp"u8;
ReadOnlySpan<byte> = nameof(Language.CSharp)u8;  // currently, doesn't support

Proposed API

ReadOnlySpan<byte> text = nameof(X)u8;

Usage Examples

MyEnumExtensions
    .IsDefined<HttpStatusCode>(nameof(HttpStatusCode.OK)u8)
    .Should()
    .BeTrue();

Alternative Designs

If $"nameof(X)"u8 were to be implemented, it would enable equivalent functionality. However, this would not resolve the asymmetry issue mentioned earlier.

Risks

I guess it depends on being able to parse nameof(X)u8, but no further concerns come to mind.

@xin9le xin9le added Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request labels Sep 3, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Language Design untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 3, 2024
@huoyaoyuan
Copy link
Member

This is a C# language feature and should go to https://github.com/dotnet/csharplang/discussions. The API request category is for API provided by the compiler, to support analyzers and IDEs etc.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2024
@xin9le
Copy link
Author

xin9le commented Sep 3, 2024

@huoyaoyuan
Thank you for your observation. I had the feeling that I might have posted in the wrong place, so I appreciate your guidance in directing me to the appropriate location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants