Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Want to override or overload StreamWriter
Message
From
06/02/2007 22:24:06
Dave Porter
Medical Systematics, Inc.
Merced, California, United States
 
 
To
06/02/2007 13:50:49
Dave Porter
Medical Systematics, Inc.
Merced, California, United States
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01192637
Message ID:
01193074
Views:
18
Hi Viv,
You would not believe how much I learned today from you! or at least you really helped me put two and two together to get four instead of some incomprehensible compiler error. You should see the light bulb floating above my head!

Why do you put the underscore in front of the variable hits? as in _hits?

FYI for the StringWriter there is a property StringWriter.NewLine that lets you get set the line terminator for sw.WriteLine() to whatever string you want!! Defaults to carriage return, but now I can easily switch back and forth! So cool!

Thanks Again!! Dave

>Hi Viv, thanks so much! I sincerely appreciate the time you have given me. You really understand what I'm trying to do! I'm going to try these out later today and I'll get back to you.
>Dave
>
>
>>Two suggestions:
>>(a) Sub-class
>>
>>//#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...
>>HTH,
>>Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform