// just the declaration with the initialization public override void VisitVariableDeclarator(VariableDeclaratorSyntax variableDeclaratorSyntax) { base.VisitVariableDeclarator(variableDeclaratorSyntax); var identifier = variableDeclaratorSyntax.Identifier; var semanticModel = _context.GetSemanticModelFor(variableDeclaratorSyntax); var symbol = semanticModel.GetDeclaredSymbol(variableDeclaratorSyntax); var vars = _variables.Peek(); VariableIdentity variableIdentity = null; if (variableDeclaratorSyntax.Initializer != null && variableDeclaratorSyntax.Initializer is EqualsValueClauseSyntax equalsValueClauseSyntax) { var right = equalsValueClauseSyntax.Value; var rightVariable = semanticModel.GetSymbolInfo(right).Symbol; if (rightVariable != null && vars.TryGetValue(rightVariable.Name, out VariableIdentity value)) { variableIdentity = VariableIdentity.FromAlias(value, symbol); } } if (variableIdentity == null) { variableIdentity = new VariableIdentity(symbol); } vars[symbol.Name] = variableIdentity; }
public override void VisitAssignmentExpression(AssignmentExpressionSyntax assignmentExpressionSyntax) { base.VisitAssignmentExpression(assignmentExpressionSyntax); var semanticModel = _context.GetSemanticModelFor(assignmentExpressionSyntax); var vars = _variables.Peek(); var symbol = semanticModel.GetSymbolInfo(assignmentExpressionSyntax.Left).Symbol; VariableIdentity variableIdentity = null; if (assignmentExpressionSyntax.Right != null && assignmentExpressionSyntax.Right is IdentifierNameSyntax identifierNameSyntax) { var rightVariable = semanticModel.GetSymbolInfo(identifierNameSyntax).Symbol; if (rightVariable != null && vars.TryGetValue(rightVariable.Name, out VariableIdentity value)) { variableIdentity = VariableIdentity.FromAlias(value, symbol); } } if (variableIdentity == null) { variableIdentity = new VariableIdentity(symbol); } vars[symbol.Name] = variableIdentity; }