Writing Object Use to Standard Output

A preponderance of fundamental SharePoint proxy objects implement the IDisposable pattern, and therefore the disposal state of such objects becomes a subject of interest, this is predominantly important when using mock object schemes. Recently, I had to do just this and it’s not actually very complicated, but I needed to remember it so decided to post it. While the goal was to make the method analogous to type, the approach can be easily schemed to SharePoint proxy objects, since as you can see it’s a very simple approach.

In the below, the new static extension method TraceUsing in class Extensions is being defined. Since we are going to follow a object, the instance represents type “T” and the Action parameter set to type “T” lets you specify an action to be performed on “T”. In my specific case, the parameter supply to Action was just a write to standard output saying that we are currently using an arbitrary object (to an HtmlTextWriter in my case).