-
Notifications
You must be signed in to change notification settings - Fork 4.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
Share common code in 'use collection expression'. #69502
Share common code in 'use collection expression'. #69502
Conversation
{ | ||
} | ||
|
||
protected override void InitializeWorker(AnalysisContext context) | ||
=> context.RegisterCompilationStartAction(context => | ||
protected override void InitializeWorker(CompilationStartAnalysisContext context) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
No description provided.