private static async Task <bool> CanRefactorAsync( RefactoringContext context, PropertyDeclarationSyntax property, ExpressionSyntax expression) { if (expression?.IsKind(SyntaxKind.SimpleAssignmentExpression) == true) { var assignment = (AssignmentExpressionSyntax)expression; ExpressionSyntax left = assignment.Left; ExpressionSyntax right = assignment.Right; if (left?.IsKind(SyntaxKind.IdentifierName) == true && right?.IsKind(SyntaxKind.IdentifierName) == true) { var identifierName = (IdentifierNameSyntax)right; if (identifierName.Identifier.ValueText == "value") { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); INamedTypeSymbol containingType = semanticModel.GetDeclaredSymbol(property, context.CancellationToken)?.ContainingType; return(containingType != null && SymbolUtility.ImplementsINotifyPropertyChanged(containingType, semanticModel)); } } } return(false); }
private static async Task <bool> ImplementsINotifyPropertyChangedAsync( RefactoringContext context, PropertyDeclarationSyntax property) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); IPropertySymbol propertySymbol = semanticModel.GetDeclaredSymbol(property, context.CancellationToken); if (propertySymbol != null) { INamedTypeSymbol containingType = propertySymbol.ContainingType; return(containingType != null && SymbolUtility.ImplementsINotifyPropertyChanged(containingType, semanticModel)); } return(false); }