Exemplo n.º 1
0
        /// <summary>
        /// Create a <see cref="SymbolAndDeclaration{IPropertySymbol, PropertyDeclarationSyntax}"/> is symbol exists.
        /// </summary>
        /// <param name="declaration">The <see cref="PropertyDeclarationSyntax"/>.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <param name="result">The <see cref="SymbolAndDeclaration{IPropertySymbol, PropertyDeclarationSyntax}"/>.</param>
        /// <returns>True if the symbol exists.</returns>
        public static bool TryCreate(PropertyDeclarationSyntax declaration, SemanticModel semanticModel, CancellationToken cancellationToken, out SymbolAndDeclaration <IPropertySymbol, PropertyDeclarationSyntax> result)
        {
            if (semanticModel.TryGetSymbol(declaration, cancellationToken, out var symbol))
            {
                result = new SymbolAndDeclaration <IPropertySymbol, PropertyDeclarationSyntax>(symbol, declaration);
                return(true);
            }

            result = default;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a <see cref="SymbolAndDeclaration{ITypeSymbol, StructDeclarationSyntax}"/> is symbol exists.
        /// </summary>
        /// <param name="declaration">The <see cref="StructDeclarationSyntax"/>.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <param name="result">The <see cref="SymbolAndDeclaration{INamedTypeSymbol, StructDeclarationSyntax}"/>.</param>
        /// <returns>True if the symbol exists.</returns>
        public static bool TryCreate(StructDeclarationSyntax declaration, SemanticModel semanticModel, CancellationToken cancellationToken, out SymbolAndDeclaration <INamedTypeSymbol, StructDeclarationSyntax> result)
        {
            if (semanticModel.TryGetNamedType(declaration, cancellationToken, out var symbol))
            {
                result = new SymbolAndDeclaration <INamedTypeSymbol, StructDeclarationSyntax>(symbol, declaration);
                return(true);
            }

            result = default;
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a <see cref="SymbolAndDeclaration{IMethodSymbol, AccessorDeclarationSyntax}"/> is symbol exists.
        /// </summary>
        /// <param name="declaration">The <see cref="AccessorDeclarationSyntax"/>.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <param name="result">The <see cref="SymbolAndDeclaration{IMethodSymbol, AccessorDeclarationSyntax}"/>.</param>
        /// <returns>True if the symbol exists.</returns>
        public static bool TryCreate(AccessorDeclarationSyntax declaration, SemanticModel semanticModel, CancellationToken cancellationToken, out SymbolAndDeclaration <IMethodSymbol, AccessorDeclarationSyntax> result)
        {
            if (semanticModel.TryGetSymbol(declaration, cancellationToken, out IMethodSymbol? symbol))
            {
                result = new SymbolAndDeclaration <IMethodSymbol, AccessorDeclarationSyntax>(symbol, declaration);
                return(true);
            }

            result = default;
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a <see cref="SymbolAndDeclaration{IEventSymbol, EventDeclarationSyntax}"/> is symbol exists.
        /// </summary>
        /// <param name="symbol">The <see cref="IEventSymbol"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <param name="result">The <see cref="SymbolAndDeclaration{IEventSymbol, EventFieldDeclarationSyntax}"/>.</param>
        /// <returns>True if the symbol exists.</returns>
        public static bool TryCreate(IEventSymbol symbol, CancellationToken cancellationToken, out SymbolAndDeclaration <IEventSymbol, EventFieldDeclarationSyntax> result)
        {
            if (symbol is null)
            {
                throw new System.ArgumentNullException(nameof(symbol));
            }

            if (symbol.TrySingleEventFieldDeclaration(cancellationToken, out var declaration))
            {
                result = new SymbolAndDeclaration <IEventSymbol, EventFieldDeclarationSyntax>(symbol, declaration);
                return(true);
            }

            result = default;
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a <see cref="SymbolAndDeclaration{IMethodSymbol, ConstructorDeclarationSyntax}"/> is symbol exists.
        /// </summary>
        /// <param name="symbol">The <see cref="IMethodSymbol"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <param name="result">The <see cref="SymbolAndDeclaration{IMethodSymbol, ConstructorDeclarationSyntax}"/>.</param>
        /// <returns>True if the symbol exists.</returns>
        public static bool TryCreate(IMethodSymbol symbol, CancellationToken cancellationToken, out SymbolAndDeclaration <IMethodSymbol, ConstructorDeclarationSyntax> result)
        {
            if (symbol is null)
            {
                throw new System.ArgumentNullException(nameof(symbol));
            }

            if (symbol.MethodKind == MethodKind.Constructor &&
                symbol.TrySingleDeclaration(cancellationToken, out ConstructorDeclarationSyntax? declaration))
            {
                result = new SymbolAndDeclaration <IMethodSymbol, ConstructorDeclarationSyntax>(symbol, declaration);
                return(true);
            }

            result = default;
            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a <see cref="SymbolAndDeclaration{INamedTypeSymbol, ClassDeclarationSyntax}"/> is symbol exists.
        /// </summary>
        /// <param name="symbol">The <see cref="INamedTypeSymbol"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <param name="result">The <see cref="SymbolAndDeclaration{INamedTypeSymbol, ClassDeclarationSyntax}"/>.</param>
        /// <returns>True if the symbol exists.</returns>
        public static bool TryCreate(INamedTypeSymbol symbol, CancellationToken cancellationToken, out SymbolAndDeclaration <INamedTypeSymbol, ClassDeclarationSyntax> result)
        {
            if (symbol is null)
            {
                throw new System.ArgumentNullException(nameof(symbol));
            }

            if (symbol.TypeKind == TypeKind.Class &&
                symbol.TrySingleDeclaration(cancellationToken, out ClassDeclarationSyntax? declaration))
            {
                result = new SymbolAndDeclaration <INamedTypeSymbol, ClassDeclarationSyntax>(symbol, declaration);
                return(true);
            }

            result = default;
            return(false);
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 public bool Equals(SymbolAndDeclaration <TSymbol, TDeclaration> other)
 {
     return(Equals(this.Symbol, other.Symbol) &&
            ReferenceEquals(this.Declaration, other.Declaration));
 }