public static int RightSideOfAssignmentCount(ISymbol variable, BlockSyntax block, SemanticModel semanticModel, CancellationToken cancellationToken) { int count = 0; using (var walker = AssignmentWalker.Borrow(block, Search.TopLevel, semanticModel, cancellationToken)) { foreach (AssignmentExpressionSyntax assignment in walker.Assignments) { var right = semanticModel.GetSymbolSafe(CastUtils.UnWrapCast(assignment.Right), cancellationToken); if (right != null && right.Equals(variable)) { count++; } } } using (var walker = VariableDeclarationWalker.Borrow(block, Search.TopLevel, semanticModel, cancellationToken)) { foreach (VariableDeclaratorSyntax delc in walker.Declarations) { var rightSymbol = semanticModel.GetSymbolSafe(CastUtils.UnWrapCast(delc.Initializer.Value), cancellationToken); if (SymbolComparer.Equals(variable, rightSymbol)) { count++; } } } return(count); }
public static void ProcessLeftSideOfAssignment(ISymbol variable, BlockSyntax block, SemanticModel semanticModel, CancellationToken cancellationToken, RefCounterStatus status) { List <AssignmentExpressionSyntax> rc = new List <AssignmentExpressionSyntax>(); using (var walker = AssignmentWalker.Borrow(block, Search.TopLevel, semanticModel, cancellationToken)) { foreach (AssignmentExpressionSyntax assignment in walker.Assignments) { var sym = ModelExtensions.GetSymbolInfo(semanticModel, assignment.Left, cancellationToken); if (variable.Equals(sym.Symbol)) { AssignmentUtils.CalcAssignmentValue(assignment.Right, block, semanticModel, cancellationToken, status); } } } }