/// <summary> /// Check if <paramref name="candidate"/> is <paramref name="symbol"/>. /// Optimized so that the stuff that can be checked in syntax mode is done before calling get symbol. /// </summary> /// <param name="candidate">The <see cref="MemberAccessExpressionSyntax"/>.</param> /// <param name="symbol">The <see cref="QualifiedField"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>True if <paramref name="candidate"/> is <paramref name="symbol"/>.</returns> public static bool IsSymbol(this MemberAccessExpressionSyntax candidate, QualifiedField symbol, SemanticModel semanticModel, CancellationToken cancellationToken) { if (candidate is null) { throw new System.ArgumentNullException(nameof(candidate)); } if (symbol is null) { throw new System.ArgumentNullException(nameof(symbol)); } return(candidate switch { { Name : IdentifierNameSyntax identifier } => identifier.IsSymbol(symbol, semanticModel, cancellationToken),
/// <summary> /// Check if <paramref name="candidate"/> is <paramref name="symbol"/>. /// Optimized so that the stuff that can be checked in syntax mode is done before calling get symbol. /// </summary> /// <param name="candidate">The <see cref="IdentifierNameSyntax"/>.</param> /// <param name="symbol">The <see cref="QualifiedField"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>True if <paramref name="candidate"/> is <paramref name="symbol"/>.</returns> public static bool IsSymbol(this IdentifierNameSyntax candidate, QualifiedField symbol, SemanticModel semanticModel, CancellationToken cancellationToken) { if (candidate is null) { throw new System.ArgumentNullException(nameof(candidate)); } if (symbol is null) { throw new System.ArgumentNullException(nameof(symbol)); } return(candidate.Identifier.ValueText == symbol.Name && semanticModel.TryGetSymbol(candidate, cancellationToken, out var candidateSymbol) && candidateSymbol == symbol); }
/// <summary> /// Check if <paramref name="candidate"/> is <paramref name="expected"/>. /// </summary> /// <param name="candidate">The <see cref="IdentifierNameSyntax"/>.</param> /// <param name="expected">The <see cref="QualifiedField"/> to match against.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <param name="target">The symbol of the target if match.</param> /// <returns>True if <paramref name="candidate"/> matches <paramref name="expected"/>.</returns> public static bool TryGetTarget(this IdentifierNameSyntax candidate, QualifiedField expected, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out IFieldSymbol?target) { if (candidate is null) { throw new System.ArgumentNullException(nameof(candidate)); } if (expected is null) { throw new System.ArgumentNullException(nameof(expected)); } target = null; return(candidate.Identifier.ValueText == expected.Name && semanticModel.TryGetSymbol(candidate, cancellationToken, out target) && target == expected); }
/// <summary> /// Check if <paramref name="candidate"/> is <paramref name="expected"/>. /// </summary> /// <param name="candidate">The <see cref="MemberAccessExpressionSyntax"/>.</param> /// <param name="expected">The <see cref="QualifiedField"/> to match against.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <param name="target">The symbol of the target if match.</param> /// <returns>True if <paramref name="candidate"/> matches <paramref name="expected"/>.</returns> public static bool TryGetTarget(this MemberAccessExpressionSyntax candidate, QualifiedField expected, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out IFieldSymbol?target) { target = null; return(candidate?.Name is IdentifierNameSyntax identifierName && identifierName.TryGetTarget(expected, semanticModel, cancellationToken, out target)); }