>>//#define DEBUGGING >> public class MyStringWriter : System.IO.StringWriter >> { >> int _hits = 0; >> >> public override void WriteLine(string s) >> { >> _hits++; >>#if (DEBUGGING) >> base.WriteLine(s); >>#else >> base.Write(s); >>#endif >> } >> >> public int Hits >> { >> get { return _hits; } >> } >> } >>>>(b) Use a static wrapper
>> public static class MyStringWriterWrapper >> { >> static System.IO.StringWriter sw = new System.IO.StringWriter(); >> static int _hits = 0; >> >> public static void WriteLine (string s) >> { >> _hits++; >>#if (DEBUGGING) >> sw.WriteLine(s); >>#else >> sw.Write(s); >>#endif >> >> } >>>>If you use the second you get automatic global access (providing there's a reference to the DLL) - just use MyStringWriterWrapper.WriteLine() wherever you need it - but you'll need to add code to access other methods/properties of the actual Stringwriter. If you sub-class you'll need to create an instance with global scope...