kamagra how much to take

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).

  1. public static class Extensions
  2. {
  3.  
  4. public static void TraceUsing<T>(this T instance, Action<T> action)
  5. {
  6. try
  7. {
  8. action(instance);
  9. }
  10. finally
  11. {
  12. var disp = instance as IDisposable;
  13. if (disp != null)
  14. {
  15. disp.Dispose();
  16. }
  17. }
  18. }
  19. }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>