Proposal: Syntax/semantics for non-static extension methods #3791
Unanswered
Lehonti
asked this question in
Language Ideas
Replies: 1 comment
-
I personally prefer |
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider a scenario like this (a data model + an object that decides how it will be represented by the GUI):
It would probably be useful to use the resolver like
plotItem.ResolveColor()
instead ofresolver.ResolveColor(plotItem)
. To that end, we could have a keyword which we would use to say "in this scope, we will be able to use the methods in this instance as extensions". Note the keyword 'extensions' in the code belowThis would also allow us to write a 'fluent interface' for objects that don't have one, and in a more flexible way than currently allowed by static extension methods. Take the above example one step further, by allowing the keyword to be applied to readonly class fields, and imagine writing something like
item. ResolveColor().GenerateLinearGradient().ToBrush()
In your opinion, what are the pros and cons of this?
Beta Was this translation helpful? Give feedback.
All reactions