dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.07k stars 4.04k forks source link

SyntaxGenerator.AttributeArgument(...) has no way of specifying which kind of argument it is in C# #43354

Closed dpoeschl closed 3 weeks ago

dpoeschl commented 4 years ago

Version Used: 16.6

See http://sourceroslyn.io/#Microsoft.CodeAnalysis.Workspaces/Editing/SyntaxGenerator.cs,101b838d04b7ec50 for the lack of this option. I tried using a normal named argument instead, but the Formatter (I think) choked on that later. Perhaps that's the bug instead, but someone who understands the SyntaxGenerator better should decide what's expected here.

dpoeschl commented 4 years ago

FYI @CyrusNajmabadi I hit this during AddParameter and generate the wrong type of named arguments in attribute construction because of it. Do you know what the expected solution to this is (is it SyntaxGenerator extension or Formatter/etc. fixing?

dpoeschl commented 4 years ago

FYI @ryzngard

CyrusNajmabadi commented 4 years ago

Yeah, sounds like a tricky thing here. We could add an internal overload that allows you to specify which kind you want. The existing one would just say "nameColon" as the type since that's what it does right now

sharwell commented 4 years ago

Here's how I implemented this for a refactoring in dotnet/roslyn-analyzers:

https://github.com/dotnet/roslyn-analyzers/blob/1edc8466e5e4cd0791e58cbac5566991c2f8c506/src/Roslyn.Diagnostics.Analyzers/Core/ImportingConstructorShouldBeObsoleteCodeFixProvider.cs#L220-L232

CyrusNajmabadi commented 3 weeks ago

Closing out due to lack of feedback.