-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Multi target analyzers #2866
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
base: master
Are you sure you want to change the base?
Multi target analyzers #2866
Conversation
…ntax model for cleaner testing of assignability. Added BDN1503. WIP need to do the same for Params.
| { | ||
| System.Diagnostics.Debugger.Launch(); | ||
| } | ||
| var hasCompilerDiagnostics = HasNoCompilerDiagnostics(string.Format(codeTemplate1, targetType, valueExpression), compilation); |
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.
Should be hasNoCompilerDiagnostics :)
| var syntaxTreesWithInterceptorsNamespaces = compilation.SyntaxTrees.Where(st => st.Options.Features.ContainsKey(InterceptorsNamespaces)); | ||
| var syntaxTree = CSharpSyntaxTree.ParseText(code); | ||
|
|
||
| var compilerDiagnostics = compilation |
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.
How do you cirmcumvent InterceptorsNamespaces here?
|
Didn't quite follow on the reasoning behind removing a lot of the logic for checking assignability. I don't really want to trigger a diagnostic if the user supplies an illegal value to the attribute, e.g. multidimensional arrays |
| return; | ||
| } | ||
|
|
||
| #if CODE_ANALYSIS_4_8 |
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.
Clever! I wasn't aware you could solve it like this by multi-targeting
| if (attributeSyntax.ArgumentList.Arguments.All(aas => aas.NameEquals != null)) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(MustHaveValuesRule, Location.Create(context.FilterTree, attributeSyntax.ArgumentList.Arguments.Span))); | ||
| context.ReportDiagnostic(Diagnostic.Create(MustHaveValuesRule, Location.Create(context.Node.SyntaxTree, attributeSyntax.ArgumentList.Arguments.Span))); |
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.
I've always used context.FilterTree here, is there any difference to context.Node.SyntaxTree?
| TypeArgumentClassMustBeNonAbstractRule, | ||
| GenericTypeArgumentClassMustBeAnnotatedWithAGenericTypeArgumentsAttributeRule, | ||
| ]; | ||
| }.ToImmutableArray(); |
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.
Is there any reason why you can't use collection expressions here?
Fixes #2863