internal static bool UsesUnderscore(this SyntaxNode node, SemanticModel semanticModel, CancellationToken cancellationToken) { using (var walker = Walker.Borrow(node, semanticModel, cancellationToken)) { if (walker.UsesThis == Result.Yes || walker.UsesUnderScore == Result.No) { return(false); } if (walker.UsesUnderScore == Result.Yes || walker.UsesThis == Result.No) { return(true); } foreach (var tree in semanticModel.Compilation.SyntaxTrees) { if (tree.FilePath.EndsWith(".g.i.cs")) { continue; } walker.Visit(tree.GetRoot(cancellationToken)); if (walker.UsesThis == Result.Yes || walker.UsesUnderScore == Result.No) { return(false); } if (walker.UsesUnderScore == Result.Yes || walker.UsesThis == Result.No) { return(true); } } } return(false); }
private static bool IsInitializedWithUninitialized(ExpressionSyntax value, SyntaxNodeAnalysisContext context, out FieldOrProperty other) { using (var walker = Walker.Borrow(value, context.SemanticModel, context.CancellationToken)) { foreach (var identifierName in walker.IdentifierNames) { if (!IsNameOf(identifierName) && context.SemanticModel.TryGetSymbol(identifierName, context.CancellationToken, out ISymbol symbol) && FieldOrProperty.TryCreate(symbol, out other) && other.IsStatic && other.ContainingType == context.ContainingSymbol.ContainingType && symbol.TrySingleDeclaration(context.CancellationToken, out MemberDeclarationSyntax otherDeclaration) && otherDeclaration.SpanStart > context.Node.SpanStart && IsInitialized(otherDeclaration)) { return(true); } } } return(false); }