Profiling guided tweaks

I decided to run the code through the CPU profiling, memory profiling and static analysis assault course and fix whatever low hanging fruit I could find.

Lots of small but hopefully simple changes. Generally things along the lines of:
* Tweaking some methods that showed up a lot in CPU profiling to make them faster.
* Tweaking methods that showed up in memory profiling to produce less garbage (typically by replacing a LINQ query with a loop so delegates don't need to be allocated).
* Following some static analysis advice, marking attributes sealed, marking some methods as static, removing unused parameters, etc.
* Changing some IDisposable stuff to follow the standard pattern where possible.
* Added some missing using statements around resources that were otherwise having to be finalized.
* Fix the solution/project files so they are consistent.

No major redesigns or anything, just tweaking what's already there (I'm aware you're in a feature freeze - I wouldn't worry about this PR too much for now since I didn't set out to fix any specific bugs or anything).

I'm hoping I've done a half decent job at following the guidelines but do point out anything that's out of place so I can be aware of it in future.