Search code examples
c#.netdisposeoverridingbinarywriter

Hooking into a BinaryWriter's Dispose


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?


Solution

  • BinaryWriter.Dispose() only contains a call to

       this.Dispose(true);
    

    so overriding Dispose(bool) will work correctly.