internal static bool TryGetDisposed(InvocationExpressionSyntax disposeCall, SemanticModel semanticModel, CancellationToken cancellationToken, out ISymbol disposed)
 {
     disposed = null;
     return(IsIDisposableDispose(disposeCall, semanticModel, cancellationToken) &&
            MemberPath.TrySingle(disposeCall, out var expression) &&
            semanticModel.TryGetSymbol(expression, cancellationToken, out disposed));
 }
 internal static bool TryGetDisposed(InvocationExpressionSyntax disposeCall, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out ISymbol?disposed)
 {
     disposed = null;
     return(IsMatchAny(disposeCall, semanticModel, cancellationToken) &&
            MemberPath.TrySingle(disposeCall, out var expression) &&
            semanticModel.TryGetSymbol(expression, cancellationToken, out disposed));
 }
        internal static bool IsDisposing(InvocationExpressionSyntax disposeCall, ISymbol symbol, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (TryGetDisposed(disposeCall, semanticModel, cancellationToken, out var disposed))
            {
                if (disposed.Equals(symbol))
                {
                    return(true);
                }

                if (disposed is IPropertySymbol property &&
                    property.TrySingleDeclaration(cancellationToken, out var declaration))
                {
                    using (var walker = ReturnValueWalker.Borrow(declaration, ReturnValueSearch.TopLevel, semanticModel, cancellationToken))
                    {
                        return(walker.TrySingle(out var returnValue) &&
                               MemberPath.TrySingle(returnValue, out var expression) &&
                               semanticModel.TryGetSymbol(expression, cancellationToken, out ISymbol nested) &&
                               nested.Equals(symbol));
                    }
                }
            }

            return(false);
        }