-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add C# code fix/refactor for new set of 'minimal' API surface areas #56283
Comments
Can I clarify this?
Also, do we really want this to be a single concern, rather than individual fixers (some of which I think we have already)? I do not know whether we have other places where we have an aggregate fixer. If not, I think these being set individually is more important than being set together - at least in existing code. |
In general we do not provide features to move back to the older styles of doing things. We instead just go in the forward direction. Note: implicit usings are neither a c# nor Roslyn thing. They are part of the .net sdk. |
Dunno, worthy of a discussion. We certainly have fixers that 'toggle' (use implicit/explicit type), so I could see that for maybe top-level statements (although once you remove the namespace, what's the 'back' 2 days later when the context is lost).
We do have some aggregate, but not a lot. This is also a good discussion point on design. I definitely could see |
Exhibit A: :-)
Right, sorry if I suggested it was...noting these are '.NET 6 and C# 10' things in my list here. Are you suggesting that changes things though as we have fixers for non-Roslyn/language things |
Is file-scoped an exception to this? IIRC, the refactoring and code-style option works both ways. Why this would be different? |
Hi Tim. First, can you fix both your posts? You're not quoting properly, making out very difficult to read. Second, as I said, "in general" :-) Note that var has bidirectionality because it's a matter of clarity. That isn't a thing for cases like nullable, or top level statements. Third:
I'm basically saying that anything related to implicit usings should likely be handled by the sdk team. They're not part of either c# or Roslyn. |
Yes. Because there's a functionality difference. For example, you cannot have multiple namespaces when using top level namespaces. So there's a way to switch. That's the same reason that we make it easy to switch from an expression bodied member to a block. It's not to 'move back', it's because you need that if you're going to have multiple statements. |
I think this warrants a discussion when a design happens here. Want to make sure we have the best customer experience if implemented by the experts in this area that know these type of experiences. |
I'm not sure what you mean. Implicit usings weren't designed here :) They're literally not a part of the language or Roslyn. No code exists in the compiler or IDE related to them at all, and they're not a C# language constructor (v10 or otherwise). They're entirely an SDK construct. Can you clarify what you'd like Roslyn to do here wrt them? -- Note: you may be thinking about 'global usings' (which are not the same as 'implicit usings'). The former is part of the language and is supported in the Roslyn Compiler and IDE. However, i'm unaware of any new feature work we intend to do there for that feature except maybe have something that detects if all your files use a particular using, and possibly suggest to you that you might want to make it into a global using. |
We have three things:
|
Note: this wasn't really about shipping the org chart. It was genuinely that literally all the code for this exists outside roslyn (and C# for that matter). It's an entirely a new concept created by the sdk, and i think all the code for it should live there :)
Yes, that's correct :)
I feel like the use case of "directly calling into main" is such a narrow case that we don't really need a special feature to handle it. If a user finds themselves in that position... well, it's just a small matter of adding |
@timheuer It sounds like your original request is for a set of refactorings which I've come to call "language migration aids". Here are some previous cases where I've filed related issues: DotNetAnalyzers/Proposals#19 As it applies to this issue, these refactorings would be designed to automate the transition of C# X to C# Y, where Y<X. It would be especially useful for cases where you need to retarget a project to an earlier framework, e.g. from Would you agree this is a correct interpretation of your request above? Assuming I have correctly interpreted your request, my next questions is: is it possible to modify (add arguments to) the |
Kinda? I still think it can be more of just a migration but as your code may shrink/grow it is a pattern that a developer may want to have. Or a team may want to enable (editorconfig) as a pattern for certain modules as a coding style. This came out of a discussion with @davidfowl as we were re-reviewing the template work specifically for Console a more bare-bones example.
This was discussed but we are not going to do that right now. |
I would be fine with a set of refactorings that moved people towards these defaults, but I do not think we want to make it easier for folks to move away from them.
I don't really think an Looking at each feature: top-level statements (no namespace/class definitions)The .NET community does not need to waste time thinking about entry points anymore and I view that as a net positive. There is nothing you cannot do in a top-level statement that would indicate we need a refactoring here. The other refactorings we offer (linq to foreach, etc.) that transform between different language forms do so because there is a real difference between them semantically. There isn't one for top-level statements and we don't really want people to go back. implicit usings (
|
We agreed on the next steps for each of the features:
|
And generally, for the question of "should we have refactorings that go both ways?" a heuristic was proposed: do we expect a modern application to have a mix of the new feature and old? One example was given of expression-bodied members: you can't use them in all places, and so even a fully modern application will still have a mix. But for something like |
@sharwell: do we still need to keep this bug open tracking any specific piece of work at this point? If we do, I admit it's not entirely clear what it is. 😄 |
filed dotnet/project-system#7586 to track the project system side of things |
Project System is tracking this in dotnet/project-system#7488. |
Consider though that unwinding a shorthand form is often just a stepping stone towards where you want to go. Using I believe the same is true of other forms, such as ternary expressions, null coalescing operators, compound assignment operators, and even for some cases constructs such as foreach/using/lock. In general it's useful to have suggestions where code can be expressed using higher level features. But sometimes when you're editing code you want to "lower" (to use compiler lingo) to a lower-level form, in order to transform your way from that point out. |
@drewnoakes How is the IDE going to know that you want to write an |
It wouldn't be a suggestion, just an optional transformation available via the lightbulb. |
Closing out as we have not heard feedback since these features were introduced that indicate that these chnages are needed. |
Brief description:
In .NET 6 and C# 10, several new defaults of glorious language enhancements were made and new experiences in tools make use of them namely in the new project/item template scenarios e.g.,
dotnet new console
The new .NET 6 console output produces an app that makes use of the following new tools/language features:
<ImplicitUsings>enable</ImplicitUsings>
)<Nullable>enable</Nullable>
)Customers may want to refactor back to older variants (or also older apps that can make use of these capabilities may want to refactor TO this pattern. A code fix created that would basically toggle usage of this when the pattern is able to be recognized.
Also having something like this that EditorConfig would support as well would be fantastic.
Languages applicable:
C#
Code example that the analyzer should report:
a single
.cs
file that has only this content (no namespaces, no 'main')The text was updated successfully, but these errors were encountered: