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 ability to provide array type conversion for a type #26225

Closed
hawkerm opened this issue May 20, 2018 · 2 comments
Closed

Add ability to provide array type conversion for a type #26225

hawkerm opened this issue May 20, 2018 · 2 comments
Milestone

Comments

@hawkerm
Copy link

hawkerm commented May 20, 2018

If I create a class and give it an implicit conversion operator:

        public SomeClass(string value) 
        {
            // ...
        }

        public static implicit operator SomeClass(string value)
        {
            return new SomeClass(value);
        }

It'd be nice to also be able to provide an array converter as well, e.g.

        public static implicit operator SomeClass[](string[] values)
        {
            return values.Select(value => new SomeClass(value)).ToArray();
        }

Currently, the implicit conversion won't happen automatically for the array (even with the singular implicit converter defined), so making an extension to the other type to provide a helper seems to be the only route but a bit messier.

Also found similar questions for this process dating back to 2010 here.

@danmoseley
Copy link
Member

danmoseley commented May 20, 2018

This seems like an initiative that should start in the Roslyn language repo. Do you want to move it there?

@karelz
Copy link
Member

karelz commented May 21, 2018

It was moved to dotnet/csharplang#1546

@karelz karelz closed this as completed May 21, 2018
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants