@@ -28,7 +28,12 @@ internal abstract partial class AbstractUseAutoPropertyAnalyzer<
2828 TFieldDeclaration ,
2929 TVariableDeclarator ,
3030 TExpression ,
31- TIdentifierName > : AbstractBuiltInCodeStyleDiagnosticAnalyzer
31+ TIdentifierName > ( ISemanticFacts semanticFacts )
32+ : AbstractBuiltInCodeStyleDiagnosticAnalyzer ( IDEDiagnosticIds . UseAutoPropertyDiagnosticId ,
33+ EnforceOnBuildValues . UseAutoProperty ,
34+ CodeStyleOptions2 . PreferAutoProperties ,
35+ new LocalizableResourceString ( nameof ( AnalyzersResources . Use_auto_property ) , AnalyzersResources . ResourceManager , typeof ( AnalyzersResources ) ) ,
36+ new LocalizableResourceString ( nameof ( AnalyzersResources . Use_auto_property ) , AnalyzersResources . ResourceManager , typeof ( AnalyzersResources ) ) )
3237 where TSyntaxKind : struct , Enum
3338 where TPropertyDeclaration : SyntaxNode
3439 where TConstructorDeclaration : SyntaxNode
@@ -48,17 +53,7 @@ internal abstract partial class AbstractUseAutoPropertyAnalyzer<
4853 /// <summary>
4954 /// Not static as this has different semantics around case sensitivity for C# and VB.
5055 /// </summary>
51- private readonly ObjectPool < HashSet < string > > _fieldNamesPool ;
52-
53- protected AbstractUseAutoPropertyAnalyzer ( )
54- : base ( IDEDiagnosticIds . UseAutoPropertyDiagnosticId ,
55- EnforceOnBuildValues . UseAutoProperty ,
56- CodeStyleOptions2 . PreferAutoProperties ,
57- new LocalizableResourceString ( nameof ( AnalyzersResources . Use_auto_property ) , AnalyzersResources . ResourceManager , typeof ( AnalyzersResources ) ) ,
58- new LocalizableResourceString ( nameof ( AnalyzersResources . Use_auto_property ) , AnalyzersResources . ResourceManager , typeof ( AnalyzersResources ) ) )
59- {
60- _fieldNamesPool = new ( ( ) => new ( this . SyntaxFacts . StringComparer ) ) ;
61- }
56+ private readonly ObjectPool < HashSet < string > > _fieldNamesPool = new ( ( ) => new ( semanticFacts . SyntaxFacts . StringComparer ) ) ;
6257
6358 protected static void AddFieldUsage ( ConcurrentDictionary < IFieldSymbol , ConcurrentSet < SyntaxNode > > fieldWrites , IFieldSymbol field , SyntaxNode location )
6459 => fieldWrites . GetOrAdd ( field , static _ => s_nodeSetPool . Allocate ( ) ) . Add ( location ) ;
@@ -78,8 +73,8 @@ private static void ClearAndFree(ConcurrentDictionary<IFieldSymbol, ConcurrentSe
7873 public override DiagnosticAnalyzerCategory GetAnalyzerCategory ( )
7974 => DiagnosticAnalyzerCategory . SemanticDocumentAnalysis ;
8075
81- protected abstract ISemanticFacts SemanticFacts { get ; }
82- protected ISyntaxFacts SyntaxFacts => this . SemanticFacts . SyntaxFacts ;
76+ private ISemanticFacts SemanticFacts { get ; } = semanticFacts ;
77+ private ISyntaxFacts SyntaxFacts => SemanticFacts . SyntaxFacts ;
8378
8479 protected abstract TSyntaxKind PropertyDeclarationKind { get ; }
8580
@@ -139,6 +134,8 @@ protected sealed override void InitializeWorker(AnalysisContext context)
139134 IsConst : false ,
140135 // Can't preserve volatile semantics on a property.
141136 IsVolatile : false ,
137+ // Can't have an autoprop that returns by-ref.
138+ RefKind : RefKind . None ,
142139 // To make processing later on easier, limit to well-behaved fields (versus having multiple
143140 // fields merged together in error recoery scenarios).
144141 DeclaringSyntaxReferences . Length : 1 ,
0 commit comments