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

Share common code in 'use collection expression'. #69502

Merged

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner August 14, 2023 23:28
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 14, 2023
{
}

protected override void InitializeWorker(AnalysisContext context)
=> context.RegisterCompilationStartAction(context =>
protected override void InitializeWorker(CompilationStartAnalysisContext context)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view with whitespace off.

.Add(s_descriptor, CodeStyleOptions2.PreferCollectionExpression)
.Add(s_unnecessaryCodeDescriptor, CodeStyleOptions2.PreferCollectionExpression))
: base(IDEDiagnosticIds.UseCollectionExpressionForArrayDiagnosticId,
EnforceOnBuildValues.UseCollectionExpressionForArray)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each subclass needs to pass in these values to make sure the analyzer applies to it.

{
if (!context.Compilation.LanguageVersion().SupportsCollectionExpressions())
return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base type does this check as it's common to all cases.

protected override void InitializeWorker(CodeBlockStartAnalysisContext<SyntaxKind> context)
{
context.RegisterSyntaxNodeAction(AnalyzeArrayInitializerExpression, SyntaxKind.ArrayInitializerExpression);
context.RegisterSyntaxNodeAction(AnalyzeArrayCreationExpression, SyntaxKind.ArrayCreationExpression);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subtypes only ned to do this registration. all the outside parts are handled by the base type.

context.RegisterSyntaxNodeAction(AnalyzeArrayCreationExpression, SyntaxKind.ArrayCreationExpression);
}

private void AnalyzeArrayCreationExpression(SyntaxNodeAnalysisContext context)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the descriptors are now instance state (As they are instance specific). so these methods became non-static.

@CyrusNajmabadi CyrusNajmabadi merged commit 394907c into dotnet:main Aug 15, 2023
@ghost ghost added this to the Next milestone Aug 15, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the useCollectionExpressionBaseType branch August 15, 2023 16:53
@dibarbet dibarbet modified the milestones: Next, 17.8 P2 Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants