public PartialTypeDeclarationProcessor(TypeDeclarationTuple partialTypeDeclaration, ReadonlyFieldCollector readonlyFieldCollector)
                {
                    this.partialTypeDeclaration = partialTypeDeclaration;
                    this.readonlyFieldCollector = readonlyFieldCollector;

                    allFields = partialTypeDeclaration.SyntaxNode.DescendantNodes()
                                .OfType <FieldDeclarationSyntax>()
                                .SelectMany(f => GetAllFields(f));
                }
        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSymbolAction(
                c =>
            {
                var declaredSymbol = (INamedTypeSymbol)c.Symbol;
                if (!declaredSymbol.IsClassOrStruct() ||
                    // Serializable classes are ignored because the serialized fields
                    // cannot be readonly. [Nonserialized] fields could be readonly,
                    // but all fields with attribute are ignored in the ReadonlyFieldCollector.
                    declaredSymbol.GetAttributes(KnownType.System_SerializableAttribute).Any())
                {
                    return;
                }

                if (declaredSymbol.DeclaringSyntaxReferences.Length > 1)
                {
                    // Partial classes are not processed.
                    // See https://github.com/dotnet/roslyn/issues/3748
                    return;
                }

                var partialDeclarations = declaredSymbol.DeclaringSyntaxReferences
                                          .Select(reference => reference.GetSyntax())
                                          .OfType <TypeDeclarationSyntax>()
                                          .Select(node =>
                                                  new SyntaxNodeAndSemanticModel <TypeDeclarationSyntax>
                {
                    SyntaxNode    = node,
                    SemanticModel = c.Compilation.GetSemanticModel(node.SyntaxTree)
                })
                                          .Where(n => n.SemanticModel != null);

                var fieldCollector = new ReadonlyFieldCollector(partialDeclarations);

                foreach (var field in fieldCollector.NonCompliantFields)
                {
                    var identifier = field.SyntaxNode.Identifier;
                    c.ReportDiagnosticIfNonGenerated(Diagnostic.Create(rule, identifier.GetLocation(), identifier.ValueText));
                }
            },
                SymbolKind.NamedType);
        }
        protected sealed override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSymbolAction(
                c =>
                {
                    var declaredSymbol = (INamedTypeSymbol)c.Symbol;
                    if (!declaredSymbol.IsClassOrStruct())
                    {
                        return;
                    }

                    if (declaredSymbol.DeclaringSyntaxReferences.Length > 1)
                    {
                        // Partial classes are not processed.
                        // See https://github.com/dotnet/roslyn/issues/3748
                        return;
                    }

                    var partialDeclarations = declaredSymbol.DeclaringSyntaxReferences
                        .Select(reference => reference.GetSyntax())
                        .OfType<TypeDeclarationSyntax>()
                        .Select(node =>
                            new SyntaxNodeSemanticModelTuple<TypeDeclarationSyntax>
                            {
                                SyntaxNode = node,
                                SemanticModel = c.Compilation.GetSemanticModel(node.SyntaxTree)
                            })
                        .Where(n => n.SemanticModel != null);

                    var fieldCollector = new ReadonlyFieldCollector(partialDeclarations);

                    foreach (var field in fieldCollector.NonCompliantFields)
                    {
                        var identifier = field.SyntaxNode.Identifier;
                        c.ReportDiagnosticIfNonGenerated(Diagnostic.Create(rule, identifier.GetLocation(), identifier.ValueText));
                    }
                },
                SymbolKind.NamedType);
        }
        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSymbolAction(
                c =>
                {
                    var declaredSymbol = (INamedTypeSymbol)c.Symbol;
                    if (!declaredSymbol.IsClassOrStruct())
                    {
                        return;
                    }

                    if (declaredSymbol.DeclaringSyntaxReferences.Count() > 1)
                    {
                        // Partial classes are not processed.
                        // See https://github.com/dotnet/roslyn/issues/3748
                        return;
                    }

                    var partialDeclarations = declaredSymbol.DeclaringSyntaxReferences
                        .Select(reference => reference.GetSyntax())
                        .OfType<TypeDeclarationSyntax>()
                        .Select(node =>
                            new SyntaxNodeSemanticModelTuple<TypeDeclarationSyntax>
                            {
                                SyntaxNode = node,
                                SemanticModel = c.Compilation.GetSemanticModel(node.SyntaxTree)
                            })
                        .Where(n => n.SemanticModel != null);

                    var fieldCollector = new ReadonlyFieldCollector(partialDeclarations);

                    foreach (var field in fieldCollector.NonCompliantFields)
                    {
                        var identifier = field.SyntaxNode.Identifier;
                        c.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, identifier.GetLocation(), identifier.ValueText));
                    }
                },
                SymbolKind.NamedType);
        }
                public PartialTypeDeclarationProcessor(TypeDeclarationTuple partialTypeDeclaration, ReadonlyFieldCollector readonlyFieldCollector)
                {
                    this.partialTypeDeclaration = partialTypeDeclaration;
                    this.readonlyFieldCollector = readonlyFieldCollector;

                    allFields = partialTypeDeclaration.SyntaxNode.DescendantNodes()
                        .OfType<FieldDeclarationSyntax>()
                        .SelectMany(f => GetAllFields(f));
                }