Expose more of Roslyn to the XPath queries of MA0240 - #1544
Merged
Merged
Conversation
Add the members that were missing from the data the banned syntax queries can select. The attributes are only computed when a query can select them, so the new ones cost nothing to the entries that do not use them. - Expose the kind of a type as the '...Kind' suffix, so a query can select the interfaces, the enumerations or the delegates instead of only telling a value type from a reference type. - Expose the modifiers of a symbol: IsAbstract, IsVirtual, IsOverride, IsSealed, IsAsync, IsExtensionMethod and Arity. The modifiers that only a method or a type has are not exposed for the other symbols, so an attribute that is not present means that the modifier does not apply. - Expose the documentation comment ids of the properties that return several symbols, which only had the qualified names and the names. - Expose a property that returns several types with the names a type has, as the types were exposed as the symbols that are not types. '@TypeArguments' is therefore '@TypeArgumentsMetadataName'. - Expose the CommonConversion of an operation, which was dropped, so a query can tell a user-defined conversion from a numeric one and reach the operator it calls. The members that are not in every supported version of Roslyn, such as IsUnion, are not exposed.
The tests that use a source generator of the .NET reference pack failed on a run with a ReflectionTypeLoadException: Could not load file or assembly 'Microsoft.Interop.SourceGeneration' GeneratorAssemblyLoader registered the path of an assembly just before loading it, so an assembly could only resolve the dependencies that were loaded before it. Microsoft.Interop.ComInterfaceGenerator and Microsoft.Interop.LibraryImportGenerator depend on Microsoft.Interop.SourceGeneration, which sorts after them, and the assemblies are enumerated with Directory.EnumerateFiles, whose order depends on the file system. The load therefore succeeded or failed depending on the machine, which is why only one leg of the CI matrix failed. Register the paths of the whole pack in the constructor, before any assembly is loaded, so the resolution no longer depends on the order.
This was referenced Sep 22, 2026
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#582
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#563
Closed
Closed
Closed
This was referenced Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the members that were missing from the data an MA0240 banned syntax query can select, and fixes two inconsistencies in how the operations are exposed.
The kind of a type
Each of the four type prefixes gains a
…Kindsuffix (semantic:TypeKind,semantic:ConvertedTypeKind,semantic:ReturnTypeKind,semantic:ContainingTypeKind, and@PKindfor the type properties of the operations). OnlyIsValueTypeandSpecialTypewere exposed, so a query could not select the interfaces, the enumerations or the delegates:The attribute is not present for the types that do not compile (
UnknownandError), likesemantic:TypeSpecialTypeis not present for the types that are not special.The modifiers of a symbol
IsAbstract,IsVirtual,IsOverride,IsSealed,IsAsync,IsExtensionMethodandArity, on thesemanticattributes and on the symbol properties of the operations (@TargetMethodIsAbstract,@TargetMethodArity, ...). OnlyIsStaticwas exposed:The modifiers that only a method or a type has are not exposed for the other symbols, so
[not(@semantic:IsAsync)]selects the nodes whose symbol is not a method, whereas[@semantic:IsAsync='false']selects the ones whose symbol is a method that is notasync. The logic is shared by the two navigators (XPathAttributeFormatter.AddSymbolModifiers), so the two lists cannot drift apart.Two inconsistencies of the operations
LocalsorInitializedFields, only had@Pand@PName. It now also has@PDocumentationId.ImmutableArray<ITypeSymbol>is now matched beforeImmutableArray<ISymbol>and exposes@PName,@PMetadataName,@PDocumentationIdand@PReferenceId.CommonConversionwas dropped byCreateProperty, soIConversionOperation.Conversionwas unreachable and a query could not tell a user-defined conversion from a numeric one. It now exposes@PExists,@PIsIdentity,@PIsImplicit,@PIsNullable,@PIsNumeric,@PIsReference,@PIsUserDefined, and the operator as the symbol@PMethod:This covers
IConversionOperation.Conversion, the two conversions ofIArgumentOperationand ofICompoundAssignmentOperation,ICoalesceOperation.ValueConversion, andISpreadOperation.ElementConversionon the versions of Roslyn that have it.IsUnionis not exposed, as it only exists from Roslyn 5.9 and an entry must mean the same thing in every supported version.Why
The operations are exposed by reflection, so they follow the API of Roslyn, but the
semanticattributes are a hand-written list that was missing the modifiers and the kind of a type. The attributes are only computed when a query can select them (XPathAttributeFilter), so the entries that do not use the new attributes pay nothing for them. The list properties declare only the names they can produce, so asking for@PIsStaticon aLocalsno longer costs a reflection call.Breaking change
@TypeArgumentsbecomes@TypeArgumentsMetadataName, as a list of types is now exposed like a single type, which has no bare@P. It only applies toIDynamicMemberReferenceOperation.TypeArguments, an attribute that was introduced recently and thatoperation:DynamicMemberReferenceis the only element to have.Testing
DoNotUseBannedSyntaxAnalyzerTests, which bring the MA0240/MA0241 tests to 153. They pass onroslyn4.8,roslyn4.14,roslyn5.0,roslyn5.6androslyn5.9.roslyn5.9test project passes (4953 tests).dotnet run --project src/DocumentationGeneratorexits 0 and changes no markdown file beyond the edits todocs/Rules/MA0240.mdthat are in this PR.