Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Tue, 8 Jul 2008 13:40:08 -0700,    group: microsoft.public.dotnet.languages.csharp        back       


Add functionality to Console.WriteLine, sort of like defining a ma   
I am trying to create a class or function which does one extra thing then 
performs a normal Console.WriteLine, preferrably with all the overloads 
available and intact.

Where I currently have:

Console.Write("\r                                                            
                   \r");
// note, the previous line is simply clearing any text on the current 
console line without leaving that lnie.
Console.WriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, var3, 
var4, var5});

I'd like to do

MyClass.OverwriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, 
var3, var4, var5});

and get the same result, with all WriteLine overloads available for 
OverwriteLine, and hopefully without having to duplicate them all.

Can anyone help me out with this?

I asked some friends and one idea was the following, and it is better than 
the extra Console.Write each time, but I am still hoping for more:

static string SomeMethod(string toPad)
{
    return "\r                                                               
                \r" + toPad;
}

Console.WriteLine(SomeMethod("here is a string {0} : {1}"), new 
object[]{"some", 5});

I'm using Framework 2.0.

Erik
date: Tue, 8 Jul 2008 13:40:08 -0700   author:   Erik Eckhardt (reverse each section)

RE: Add functionality to Console.WriteLine, sort of like defining a ma   
There isnt any way to add a static method to the Console class but you can 
easily make your own with passed through the calls to the Console class but 
adds your prefix on to the string. 
The suggestion of having a function to do that probably isnt terrible either 
as you are really stuck for options with what you want to do as far as I know.


-- 
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com


"Erik Eckhardt" wrote:

> I am trying to create a class or function which does one extra thing then 
> performs a normal Console.WriteLine, preferrably with all the overloads 
> available and intact.
> 
> Where I currently have:
> 
> Console.Write("\r                                                            
>                    \r");
> // note, the previous line is simply clearing any text on the current 
> console line without leaving that lnie.
> Console.WriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, var3, 
> var4, var5});
> 
> I'd like to do
> 
> MyClass.OverwriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, 
> var3, var4, var5});
> 
> and get the same result, with all WriteLine overloads available for 
> OverwriteLine, and hopefully without having to duplicate them all.
> 
> Can anyone help me out with this?
> 
> I asked some friends and one idea was the following, and it is better than 
> the extra Console.Write each time, but I am still hoping for more:
> 
> static string SomeMethod(string toPad)
> {
>     return "\r                                                               
>                 \r" + toPad;
> }
> 
> Console.WriteLine(SomeMethod("here is a string {0} : {1}"), new 
> object[]{"some", 5});
> 
> I'm using Framework 2.0.
> 
> Erik
date: Tue, 8 Jul 2008 17:41:00 -0700   author:   Ciaran O''Donnell

RE: Add functionality to Console.WriteLine, sort of like defining   
Thanks for the reply.

In order to do what you've suggested I'd have to put in code to handle every 
override of Console.WriteLine, wouldn't I?

This seems like something that should be so easy...

macro OverwriteLine(params) {Console.Write("\n  ...   \n"); 
Console.WriteLine(params);}

or something like that :)

Do you have a suggestion as to the easiest/fastest way to get all the 
redirecting of overrides in place? Anyway, the code complexity seems too much 
for the slight benefit it would give. Oh well.

-- 

"Ciaran O''Donnell" wrote:

> There isnt any way to add a static method to the Console class but you can 
> easily make your own with passed through the calls to the Console class but 
> adds your prefix on to the string. 
> The suggestion of having a function to do that probably isnt terrible either 
> as you are really stuck for options with what you want to do as far as I know.
> 
> 
> -- 
> Ciaran O''Donnell
> http://wannabedeveloper.spaces.live.com
> 
> 
> "Erik Eckhardt" wrote:
> 
> > I am trying to create a class or function which does one extra thing then 
> > performs a normal Console.WriteLine, preferrably with all the overloads 
> > available and intact.
> > 
> > Where I currently have:
> > 
> > Console.Write("\r                                                            
> >                    \r");
> > // note, the previous line is simply clearing any text on the current 
> > console line without leaving that lnie.
> > Console.WriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, var3, 
> > var4, var5});
> > 
> > I'd like to do
> > 
> > MyClass.OverwriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, 
> > var3, var4, var5});
> > 
> > and get the same result, with all WriteLine overloads available for 
> > OverwriteLine, and hopefully without having to duplicate them all.
> > 
> > Can anyone help me out with this?
> > 
> > I asked some friends and one idea was the following, and it is better than 
> > the extra Console.Write each time, but I am still hoping for more:
> > 
> > static string SomeMethod(string toPad)
> > {
> >     return "\r                                                               
> >                 \r" + toPad;
> > }
> > 
> > Console.WriteLine(SomeMethod("here is a string {0} : {1}"), new 
> > object[]{"some", 5});
> > 
> > I'm using Framework 2.0.
> > 
> > Erik
date: Wed, 9 Jul 2008 09:17:01 -0700   author:   Erik Eckhardt (reverse each section)

RE: Add functionality to Console.WriteLine, sort of like defining   
Its basic in terms of logic and idea but in OO practises it isnt something 
that should be easy really. Console is an object with methods on it and to 
change those you have to redefine them in some way. If they were instance 
methods then you would need to inherit from Console and override them all.
But they are static so you need to wrap them up inside a new class with new 
statics.
They may well be a way to get access to the Windows API to intercept writes 
to the stdout stream but the writes are done 1 character at a time so you 
wouldnt know when to inject the carriage return characters.
Would you really need to wrap ALL the write methods on console. perhaps you 
could limit yourself to use using Writeline(sring) and Writeline(string, 
params object[])





-- 
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com


"Erik Eckhardt" wrote:

> Thanks for the reply.
> 
> In order to do what you've suggested I'd have to put in code to handle every 
> override of Console.WriteLine, wouldn't I?
> 
> This seems like something that should be so easy...
> 
> macro OverwriteLine(params) {Console.Write("\n  ...   \n"); 
> Console.WriteLine(params);}
> 
> or something like that :)
> 
> Do you have a suggestion as to the easiest/fastest way to get all the 
> redirecting of overrides in place? Anyway, the code complexity seems too much 
> for the slight benefit it would give. Oh well.
> 
> -- 
> 
> "Ciaran O''Donnell" wrote:
> 
> > There isnt any way to add a static method to the Console class but you can 
> > easily make your own with passed through the calls to the Console class but 
> > adds your prefix on to the string. 
> > The suggestion of having a function to do that probably isnt terrible either 
> > as you are really stuck for options with what you want to do as far as I know.
> > 
> > 
> > -- 
> > Ciaran O''Donnell
> > http://wannabedeveloper.spaces.live.com
> > 
> > 
> > "Erik Eckhardt" wrote:
> > 
> > > I am trying to create a class or function which does one extra thing then 
> > > performs a normal Console.WriteLine, preferrably with all the overloads 
> > > available and intact.
> > > 
> > > Where I currently have:
> > > 
> > > Console.Write("\r                                                            
> > >                    \r");
> > > // note, the previous line is simply clearing any text on the current 
> > > console line without leaving that lnie.
> > > Console.WriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, var3, 
> > > var4, var5});
> > > 
> > > I'd like to do
> > > 
> > > MyClass.OverwriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, 
> > > var3, var4, var5});
> > > 
> > > and get the same result, with all WriteLine overloads available for 
> > > OverwriteLine, and hopefully without having to duplicate them all.
> > > 
> > > Can anyone help me out with this?
> > > 
> > > I asked some friends and one idea was the following, and it is better than 
> > > the extra Console.Write each time, but I am still hoping for more:
> > > 
> > > static string SomeMethod(string toPad)
> > > {
> > >     return "\r                                                               
> > >                 \r" + toPad;
> > > }
> > > 
> > > Console.WriteLine(SomeMethod("here is a string {0} : {1}"), new 
> > > object[]{"some", 5});
> > > 
> > > I'm using Framework 2.0.
> > > 
> > > Erik
date: Thu, 10 Jul 2008 03:41:02 -0700   author:   Ciaran O''Donnell

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us