-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for Static Extensions #2334
Comments
Would #1988 solve your issues? |
Its a similar issue, but there is no solution to that issue. |
Yes there is. It suggests that you should be allowed to just make your own class called ConfigurationManager and reference both directly. |
Thats a suggestion for a feature that does not exist. Not a solution to the existing features. |
There is no existing solution for the feature you're looking for. That issue is a proposal to look into adding such a feature. If you have a different idea as to how to implement such a proposal feel free to write one up.
The reason the syntax you attempted failed is because you can't declare a parameter or a variable of a |
Yeah sorry I thought it was clear it was a feature suggestion. I guess I forgot to add the tag. I understand there's not a current solution
Get Outlook for Android<https://aka.ms/ghei36>
…________________________________
From: HaloFour <notifications@github.com>
Sent: Tuesday, March 12, 2019 12:04:06 PM
To: dotnet/csharplang
Cc: Andrew Mills; Author
Subject: Re: [dotnet/csharplang] Allow for Static Extensions (#2334)
Not a solution to the existing features.
There is no existing solution for the feature you're looking for. That issue is a proposal to look into adding such a feature. If you have a different idea as to how to implement such a proposal feel free to write one up.
What is the purpose of not allowing this ability to make static extensions? Id love to see them in a future update.
The reason the syntax you attempted failed is because you can't declare a parameter or a variable of a static class. It doesn't make any sense to. Something like "static extension methods" would have to be a new feature that has to go through a separate design process.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#2334 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AGIGN0xVIruPkmIltPt9vpUu4SgOMGe1ks5vV8_2gaJpZM4bq71m>.
|
But the feature suggestion as is makes no sense syntactically. Adding a parameter of a static type is meaningless. It will have to be reworked syntactically, at which point I imagine it will look something like #1988. |
Yes, and im sure your suggestion works theoretically, but its not a solution. Which is why i said your proposed solution is just that, a proposal, not a solution. |
This will likely fall out naturally from the discussion/proposal around "extension everything" which aims to expand on extension methods to support other members, both static and instance, and possibly even interface implementations: |
But can't you write a more conventional static method and just drop the this? Yeah you won't get intellisense on that type (Configuration manager) but you will get it from the namespace where the static function is imported... E g. ConfigurationManagerHelper... Optionally use composition to make a class which gets a ConfigurationManager and add you methods to that class. I wouldn't say this feature makes no sense it's just tricky especially when using constructs are in play and requires us to jump through hoops when we encounter this paradigm.. e.g. ServicePointManager et al |
I am hoping to get rid of wrapper classes. I love the idea of extension classes but I cannot add an extension method to a static class. For example: I want extension methods for ConfigurationManager. So when i try to add an extension method to a static class I get the error "'ConfigurationManager': static types cannot be used as parameters" for the following code.
Doing this forces me to change my class to a wrapper class.
so now instead of going using the following code:
ConfigurationManager.RunSettings()
Where ConfigurationManger is well known class used in the System.Configuration namespace. I now have to tell my developers to use the Wrapper class
ConfigurationManagerWrapper.RunSettings()
What is the purpose of not allowing this ability to make static extensions? Id love to see them in a future update. I would find this extremely useful
The text was updated successfully, but these errors were encountered: