Expand Namespaces interrogated for use with Extension Methods #1671
Replies: 8 comments
-
If anything, using marker interfaces is considered an anti-pattern.
So why are you not putting those extension methods in the same namespace? 🤔 Also, this would be a massive breaking change, as it could suddenly add ambiguous extension methods in scope where there previously was not. |
Beta Was this translation helpful? Give feedback.
-
I am though. The extension methods are located in the same namespace as the marker interface. They are just consumed from a different namespace. |
Beta Was this translation helpful? Give feedback.
-
This would add a third level of namespace lookup that I think would be confusing. The compiler would have to target instance members first (obviously), then imported namespaces and then the namespace of the target type. |
Beta Was this translation helpful? Give feedback.
-
I disagree that it would be confusing. Resolving otherwise erroneous cases with what is apparently a desired behaviour takes burden out of a programmer. I think the idea is a good one. |
Beta Was this translation helpful? Give feedback.
-
If you own the interface then you could just put your extensions in the global namespace, then they will always be available.
… On 28 Jun 2018, at 09:09, Jiří Veselka ***@***.***> wrote:
I disagree that it would be confusing. Resolving otherwise erroneous cases with what is apparently a desired behaviour takes burden out of a programmer. I think the idea is a good one.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Beta Was this translation helpful? Give feedback.
-
@louthy That's true, but that would introduce static classes holding those extensions into scope everywhere as well. |
Beta Was this translation helpful? Give feedback.
-
@zippec: You make that sound as if it were a problem. If it is, why? |
Beta Was this translation helpful? Give feedback.
-
Now championed at #4029 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Often times I find myself using empty, "Marker" interfaces and then putting all of the static members into extension methods as shown below. The problem with that is that I have to then add a using statement in order to be able to use the extension methods that are specifically designed for my interface. I would like to request that the namespace of the object, and namespaces of any interfaces it implements, always be searched for extension methods so the following would work:
This would also greatly aide in the "Discoverability" of extension methods.
Main code:
Beta Was this translation helpful? Give feedback.
All reactions