/// <summary> /// Gets the declared symbol and root operation from the passed in declarationSyntax and calls /// <see cref="IsSymbolAssignedPossiblyNullValue(SemanticModel, IOperation, ISymbol)"/>. Note /// that this is bool and not bool? because we know that the symbol is at the very least declared, /// so there's no need to return a null value. /// </summary> public static bool IsDeclaredSymbolAssignedPossiblyNullValue(SemanticModel semanticModel, SyntaxNode declarationSyntax, CancellationToken cancellationToken) { var declaredSymbol = semanticModel.GetRequiredDeclaredSymbol(declarationSyntax, cancellationToken); var declaredOperation = semanticModel.GetRequiredOperation(declarationSyntax, cancellationToken); var rootOperation = declaredOperation; // Walk up the tree to find a root for the operation // that contains the declaration while (rootOperation is not IBlockOperation && rootOperation.Parent is not null) { rootOperation = rootOperation.Parent; } return(IsSymbolAssignedPossiblyNullValue(semanticModel, rootOperation, declaredSymbol) == true); }