Discussion: Allow and can detect private extension methods inside non-static classes #2571
Replies: 6 comments
-
Another approach could be by relaxing CS1109 to allow extension methods inside nested static classes. |
Beta Was this translation helpful? Give feedback.
-
This sounds very similar to dotnet/roslyn#16271, which was moved to #301. |
Beta Was this translation helpful? Give feedback.
-
It would allow all C# developers to write more readable fluent code. Please do it soon. |
Beta Was this translation helpful? Give feedback.
-
And I feel it has no side effect for language spec. |
Beta Was this translation helpful? Give feedback.
-
I would like this very much. Very often, you would want to use a more fluent syntax for a rather specific thing but justifying a public extension method being placed in a separate class feels too much. By having the ability to declare local extension methods, this could be scoped very nicely. This is very similar to #301 but “extension methods everywhere” feels like a very huge thing (justifying its “likely never” milestone) while this particular thing feels very doable since it has very little effect on other things. |
Beta Was this translation helpful? Give feedback.
-
My intention is same as you. We can expand syntactic rules for C#, but I feel it's very hard work. So I made it simplicity and understandable for conflicting. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussion: Allow and can detect private extension methods inside non-static classes
Summary
Support private extension methods inside non-static classes. Specifically, allow locally usable extension methods.
Motivation
Currently, the extension methods allowed inside only static classes even so if we need it for locally.
Detailed design
For example:
Will change the extension rules:
this
keyword at first argument.Beta Was this translation helpful? Give feedback.
All reactions