Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 971307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:56:37+00:00 2026-05-16T02:56:37+00:00

My project has many reader and writer classes. I started implementing IDisposable, but I

  • 0

My project has many reader and writer classes. I started implementing IDisposable, but I believe that it adds many boilerplate code to my classes. For each of the classes, I need to implement:

  • A destructor.
  • A Dispose() method.
  • A Dispose(bool disposing) method.
  • A “bool disposed” field.
  • A check to see if the object is already disposed on every single public method.
  • Documentation (since I have the documentation flag enabled and the compiler warns otherwise).

My questions:

Is it worth to implement IDisposable? Previously, I used my classes like:

using (Stream s = File.OpenRead("myfile.bin"))
    x = new SomethingReader(s).ReadSomething();

With IDisposable, it doesn’t improve much:

using (SomethingReader r = new SomethingReader(File.OpenRead("myfile.bin")))
    x = r.ReadSomething();

Can I ONLY implement the Dispose() method?

My class doesn’t use unmanaged resources, so Dispose(false) does nothing. Since what I’m cleaning is IDisposable too, suposedly calling my methods after the object has been disposed should throw a ObjectDisposedException since I’m using an already disposed object.

If you recommend implementing the full IDisposable pattern, is there any way to reduce the boilerplate code?

EDIT: Since some answers recommend sealing the class, I can confirm that, in fact, there isn’t any problem by sealing the class.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:56:38+00:00Added an answer on May 16, 2026 at 2:56 am

    If you’re not holding unmanaged resources directly (i.e. even SafeHandle is not holding them directly), then in general:

    • Don’t implement the finalizer
    • Don’t implement Dispose(bool)
    • DO mark your class as sealed.

    It is a great pity that for years all the widely distributed documentation for IDispose was intended for people writing interop libraries (i.e. the .NET framework authors themselves), and completely ignored a much more common usage pattern for everyone else.

    Things have improved, and there is now a more lightweight pattern recognised by fxcop (VS Code Analysis) for sealed types: http://msdn.microsoft.com/en-us/library/ms244737%28VS.80%29.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a sub-project 'commonUtils' that has many generic code-snippets used across the parent
I am adding MVC to a project that has MANY legacy webform pages. This
I'm working on a project that has many iframes that are opened and closed
I am trying to create nested routes for a project that has many boards.
We have a project that has two one to many relationships. We encounter a
ok i have a project which has many gridview in its pages... now i
I'm building WPF client application. I'm following MVC pattern. The project solution has many
In a project, one of my entities is House which has many enumeration properties
My project has many roles: admin, HR, manager, employee. How do I implement it
I have a partial, that will be used in many places of a project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.