Example #1
0
        /// <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="QualifiedProperty"/>.</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, QualifiedProperty 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);
        }
Example #2
0
        /// <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="QualifiedProperty"/> 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, QualifiedProperty expected, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out IPropertySymbol?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);
        }
Example #3
0
 /// <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="QualifiedProperty"/> 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, QualifiedProperty expected, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out IPropertySymbol?target)
 {
     target = null;
     return(candidate?.Name is IdentifierNameSyntax identifierName &&
            identifierName.TryGetTarget(expected, semanticModel, cancellationToken, out target));
 }