public static Task <Document> AddCallToOnPropertyChangedInProp(Document document, Diagnostic diagnostic, SyntaxNode root) { var compilationUnit = root as CompilationUnitSyntax; var node = compilationUnit.FindNode(diagnostic.Location.SourceSpan).FirstAncestorOrSelf <PropertyDeclarationSyntax>(); var newRoot = root; if (node.AccessorList.Accessors[1].Body == null) { (newRoot, node) = ConvertToFullProperty(newRoot, node); } (newRoot, node) = AddCallToOnPropertyChanged(newRoot, node.AccessorList.Accessors[1]); var cls = node.FirstAncestorOrSelf <ClassDeclarationSyntax>(); if (!OnPropertyChangedHelper.ImplementsOnPropertyChanged(cls)) { newRoot = OnPropertyChangedHelper.CreateOnPropertyChanged(newRoot, cls); } return(Task.FromResult(document.WithSyntaxRoot(newRoot))); }
private void SyntaxNodeAction(SyntaxNodeAnalysisContext node) { var classNode = node.Node as ClassDeclarationSyntax; if (classNode.BaseList == null || classNode.BaseList.Types == null) { return; } if (OnPropertyChangedHelper.ImplementsOnPropertyChanged(classNode)) { return; } foreach (var tp in classNode.BaseList.Types.Select(x => x.Type).OfType <SimpleNameSyntax>()) { if (tp.Identifier.Text == "INotifyPropertyChanged") { var diag = Diagnostic.Create(Rule, classNode.Identifier.GetLocation()); node.ReportDiagnostic(diag); } } }