Skip to content
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

[New API] IsIterator field on DeclarationModifiers type #75388

Open
CoolCoderSuper opened this issue Oct 4, 2024 · 3 comments
Open

[New API] IsIterator field on DeclarationModifiers type #75388

CoolCoderSuper opened this issue Oct 4, 2024 · 3 comments
Labels
Area-IDE Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@CoolCoderSuper
Copy link

CoolCoderSuper commented Oct 4, 2024

Background and Motivation

For quick reference the file can be found here
The purpose of this api is to solve this issue in the make member static analyzer.

C# does not have the explicit Iterator api and when using the SyntaxGenerator the modifier is dropped.
The type already has features that are language specific (ie IsUnsafe) so I would see no harm in supporting this as well.

This would bring the option for generators to create iterator methods closer to reality (not necessarily important).

Proposed API

namespace Microsoft.CodeAnalysis.Editing
{
     public readonly record struct DeclarationModifiers
     {
+           public bool IsIterator => (_modifiers & Modifiers.Iterator ) != 0;
     }

This would also include the corresponding WithIterator() api.

Usage Examples

Alternative Designs

Not having the API and having language specific code in the analyzer.

Risks

Possible confusion since it only exists in VB.

@CoolCoderSuper CoolCoderSuper added Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request labels Oct 4, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 4, 2024
@CyrusNajmabadi
Copy link
Member

Why does this need to be public? As opposed to just fixing GetModifiers to include this data internally to ensure that WithModifiers doesn't remove the modifier?

@CoolCoderSuper
Copy link
Author

I suppose it wouldn't have to be but this would allow new generation to have the modifier applied.
But maybe that doesn't matter since you would still have to deal with yield return vs Yield.

@CoolCoderSuper
Copy link
Author

@CyrusNajmabadi just so I understand, your proposal would be the same just internal rather than public?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants