internal static bool IsMemberDisposed(ISymbol member, IMethodSymbol disposeMethod, SemanticModel semanticModel, CancellationToken cancellationToken) { if (member == null || disposeMethod == null) { return(false); } foreach (var reference in disposeMethod.DeclaringSyntaxReferences) { var node = reference.GetSyntax(cancellationToken) as MethodDeclarationSyntax; using (var pooled = DisposeWalker.Create(disposeMethod, semanticModel, cancellationToken)) { foreach (var invocation in pooled.Item) { if (IsDisposing(invocation, member, semanticModel, cancellationToken)) { return(true); } } } using (var pooled = IdentifierNameWalker.Create(node)) { foreach (var identifier in pooled.Item.IdentifierNames) { var memberAccess = identifier.Parent as MemberAccessExpressionSyntax; if (memberAccess?.Expression is BaseExpressionSyntax) { var baseMethod = semanticModel.GetSymbolSafe(identifier, cancellationToken) as IMethodSymbol; if (baseMethod?.Name == "Dispose") { if (IsMemberDisposed(member, baseMethod, semanticModel, cancellationToken)) { return(true); } } } if (identifier.Identifier.ValueText != member.Name) { continue; } var symbol = semanticModel.GetSymbolSafe(identifier, cancellationToken); if (member.Equals(symbol) || (member as IPropertySymbol)?.OverriddenProperty?.Equals(symbol) == true) { return(true); } } } } return(false); }
internal static Result IsMemberDisposed(ISymbol member, ITypeSymbol context, SemanticModel semanticModel, CancellationToken cancellationToken) { if (!(member is IFieldSymbol || member is IPropertySymbol) || context == null) { return(Result.Unknown); } using (var pooled = DisposeWalker.Create(context, semanticModel, cancellationToken)) { return(pooled.Item.IsMemberDisposed(member)); } }