[Proposal] Keyword to implement interface through member. #3221
Replies: 3 comments
-
Duplicate of #900. In the mean time, you can make use of the built-in codefix to write all of that code out for you. |
Beta Was this translation helpful? Give feedback.
-
I believe this would be quite easily solved with source generators. |
Beta Was this translation helpful? Give feedback.
-
This is not the same as #900, as it doesn't compromise type safety nor developer intent. This is just a syntactical sugar change in the same vein as null coalescence - already doable, but common enough that it's simplified. Implementing an interface through another object is also a fairly common and well established pattern. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Syntactic sugar, but given some interface:
It would be great to have syntax that automatically expands a class to implement an interface through a member, such as:
expands into
This just saves a lot of boilerplate code. Any member that returns an IFoo, be it a field, property, or method, may be a viable keyword target. Additionally there may be a keyword to signify that the compiler should generate explicit interface members.
If the author defines any class members that match an interface member then the compiler will not generate a wrapper member. If the author used a keyword to generate an explicit interface implementation, then an explicit interface member will be generated even if there is a matching class member unless the class member is also an explicit interface member.
Beta Was this translation helpful? Give feedback.
All reactions