private static void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{
var syntaxRoot = context.Tree.GetRoot(context.CancellationToken);
var interfaceDeclarations =
syntaxRoot.DescendantNodes(DoNotDescendIntoTypeDeclarations).Where(NodeIsInterfaceDeclaration).ToList();
var propertyDeclarations = from node in interfaceDeclarations
from property in node.DescendantNodes()
.Where(NodeIsPropertyDeclaration)
.Cast<PropertyDeclarationSyntax>()
where !PropertyHasIgnoreRuleAttribute(property,
SuppressionAttributes)
let interfaceNode = node as InterfaceDeclarationSyntax
select new
{
interfaceName = interfaceNode.Identifier.Text,
property
};
foreach (var propertyDeclaration in propertyDeclarations)
{
propertyDeclaration.property.DescendantNodesAndTokens()
.Where(n => n.IsKind(SyntaxKind.SetKeyword))
.TryFirst()
.Match()
.Some()
.Do(setter => context.ReportDiagnostic(Diagnostic.Create(Rule,
setter.AsToken()
.GetLocation(),
propertyDeclaration.property
.Identifier,
propertyDeclaration
.interfaceName)))
.IgnoreElse()
.Exec();
}
}