0

I would like to make writing more comfortable for a user of my class by offering them a BinaryWriter that, upon disposal, automatically adds its data to some internal queue.

For this purpose, I would like to write a subclass of BinaryWriter and override its Dispose method. However, Dispose is not virtual. Is it sufficient to hook into Dispose(bool)? Or is there a better approach?

mafu
  • 31,798
  • 42
  • 154
  • 247

1 Answers1

5

BinaryWriter.Dispose() only contains a call to

   this.Dispose(true);

so overriding Dispose(bool) will work correctly.

user1112560
  • 185
  • 1
  • 8
  • 1
    +1 `Dispose()` is just a wrapper around the `IDisposable.Dispose(bool)` which is exactly the overload you want to override. Notice that `Dispose()` is public for external code consumption and `Dispose(bool)` is protected virtual. The reason is a bit obvious – Leo Sep 26 '14 at 03:49