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

A generic API for string-like objects #18418

Closed
int19h opened this issue Sep 3, 2016 · 2 comments
Closed

A generic API for string-like objects #18418

int19h opened this issue Sep 3, 2016 · 2 comments
Assignees
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Runtime
Milestone

Comments

@int19h
Copy link

int19h commented Sep 3, 2016

.NET is missing a convenient way to define a method that can take something "string-like" with minimal overhead. Most existing APIs just take String, meaning that callers need to call ToString, often creating full copies that are then used only to look at a few characters at the beginning. Some types that are commonly affected by this are StringBuilder and Uri.

This could be solved by adopting a common interface like IString for all these types, which could offer the same operations that String does; and implementing that interface on all standard types that have string as a public representation of any valid value.

The closest existing equivalent is Java CharSequence.

@KrzysztofCwalina
Copy link
Member

I am not a big fan of string abstraction (or in general abstractions for language primitives). Abstractions add complexity and performance overhead that often cannot be afforded int he very primitive types.

But I do agree that there is a problem with ToString allocations. Take a look at https:/dotnet/corefxlab/wiki/System.Text.Formatting for how we are exploring to fix that.

@AlexGhiondea
Copy link
Contributor

I agree with @KrzysztofCwalina - I am not convinced we need the IString abstraction.

The allocations that StringBuilder incurs should be solved by the new StringFormatter class.

Feel free to reopen if you have other scenarios where this would be useful.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Runtime
Projects
None yet
Development

No branches or pull requests

4 participants