Generic BinaryReader/Writer Read/Write methods
I'm guessing you defined more write methods than this? Otherwise the Write() would call itself recursively infinitely. You probably have overloads for every supported type, making the generic write method superfluous. This would also explain the weird casting you are doing. I'm guessing an overloaded function with a specific type has precedence over a generic method, which is why it could work. This however, doesn't make it a clean solution.

Your Read() method seems to be more useful. Instead of throwing a ArgumentException I would prefer throwing a NotSupportedException.

As a sidenote, are you sure you want to make these extension methods of Stream and not some more specific stream? Stream can be any type of stream.



In what way is this an improvement over using BinaryWriter/BinaryReader? For the purposes I gather from your code I would only create a Read&lt;T&gt; extension method for BinaryReader.

If you feel like experimenting a bit, there might be a more performant/cleaner solution, although you'll have to benchmark to be sure. You could create a Dictionary&lt;Type, Func&lt;object&gt;&gt; to hold a matching 'reader' for every type. Initializing the delegates to store in this dictionary is the tough part, on which information can be found in this article. Most likely this is not worth the effort, although it still is a very interesting article. :) Be sure to also check out the same solution implemented by using Expression Trees in the comments of the article. For a similar implementation example I did, check out this question I posted on Code Review.