Allow more flexibility to extension method definitions #4511
Unanswered
MithrilMan
asked this question in
Language Ideas
Replies: 2 comments
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Background and Motivation
Actually you can define an extension method only within a static, top level class.
To not pollute solution with a file/class that just holds extension methods that are meant to be used in a specific class, having a way to define such method within the class itself would help having a higher code management.
The behavior could be
Proposed API
I'd propose a keyword to be used to define an extension method within any class
let's call it
extension
a definition of such method could include
Usage Examples
Suppose I've a class Foo and I want to be able to work (maybe in fluent like syntax like the example) on an instance of a Bar class, I'd like to be able to define my Foo class in a way similar to this
I don't mind about accessor or not (maybe it could be useful to hide it to inherited classes)
Feedback is welcome,
Thanks
Beta Was this translation helpful? Give feedback.
All reactions