Expose the kind-specific modifiers of the symbols in the XPath queries of MA0240
What changed
The symbol attributes of MA0240 were the same for every kind of symbol, so the modifiers of a parameter or of a field could not be queried from the syntax tree (semantic:) or from the operations (@Parameter…, @Field…, @Local…). They are now added according to the kind of the symbol:
| Symbol | semantic: attributes | Operation attributes (property P) |
|---|---|---|
| Parameter | RefKind, IsParams, IsOptional | @PRefKind, @PIsParams, @PIsOptional |
| Field | IsConst, IsReadOnly | @PIsConst, @PIsReadOnly |
| Local | RefKind, IsConst | @PRefKind, @PIsConst |
Like IsAsync and Arity, an attribute is not present when the modifier does not apply to the symbol, and is false when it applies and is not set.
Examples:
//Parameter[@semantic:RefKind='Out']
//operation:ParameterReference[@ParameterRefKind='Out']
//operation:FieldReference[@FieldIsReadOnly='false' and @FieldIsConst='false']
Notes for reviewers
RefKind.RefReadOnlyis an alias ofRefKind.In, andEnum.ToStringdoes not choose the same name on every runtime (.NET returnsIn, .NET Framework in Visual Studio may not).XPathAttributeFormatter.GetRefKindNamealways returnsIn, and the existing@RefKindattribute of thesymbol:elements now uses it too, so the value is the same on every runtime.IsReadOnlyis not exposed for properties and methods, norRefKindfor methods and properties, as the Roslyn properties mean something else there (no setter,readonlymember, by-ref return). They remain available on thesymbol:elements.- The documentation of MA0240 describes the new attributes.
Tests
New tests in DoNotUseBannedSyntaxAnalyzerTests for the semantic attributes, the operation attributes, the absence of the attributes for the other kinds of symbols, and @RefKind='In' on the symbol tree. DoNotUseBannedSyntaxAnalyzerTests passes on Roslyn 4.8, 4.14, 5.0, 5.6 and 5.9, and dotnet run --project src/DocumentationGenerator reports no changes.