Skip to content

Implementations of IDisposable should check private disposed field in public/internal/protected methods #41

@jimmyheaddon

Description

@jimmyheaddon

Linked in dotnet/roslyn-analyzers#293.

Essentially if a class correctly implements the IDisposable pattern, then public/internal/protected methods should throw ObjectDisposedException(this.GetType().FullName) as per the majority of .NET framework classes (e.g. Socket).

if (this.disposed)
{
    throw new ObjectDisposedException(this.GetType().FullName);
}

Optionally an XML comment should be declared to reflect this:

/// <exception cref="ObjectDisposedException">Thrown if this instance of <see cref="ClassName" /> has been disposed.</exception>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions