Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Extend "System.Console" #379

Open
JechoJekov opened this issue Feb 4, 2015 · 3 comments
Open

Extend "System.Console" #379

JechoJekov opened this issue Feb 4, 2015 · 3 comments
Assignees

Comments

@JechoJekov
Copy link

JechoJekov commented Feb 4, 2015

The JS "console" object provides much useful functionality which is not currently available in mscorlib. Namely it is possible print objects instead of just strings which could be very useful for debugging. Currently I'm using the following additional methods:

[InlineCode("console.log({obj})")]
public static void Log(object obj)
{
}

[InlineCode("console.log({*objects})")]
public static void Log(params object[] objects)
{
}

[InlineCode("console.info({obj})")]
public static void Info(object obj)
{
}

[InlineCode("console.info({*objects})")]
public static void Info(params object[] objects)
{
}

[InlineCode("console.warn({obj})")]
public static void Warn(object obj)
{
}

[InlineCode("console.warn({*objects})")]
public static void Warn(params object[] objects)
{
}

[InlineCode("console.error({obj})")]
public static void Error(object obj)
{
}

[InlineCode("console.error({*objects})")]
public static void Error(params object[] objects)
{
}

[InlineCode("console.trace()")]
public static void PrintStackTrace()
{
}

There are also some other methods that could be useful like:

  1. group()
  2. groupEnd()
  3. time()
  4. timeEnd()
@nippur72
Copy link
Contributor

There is also the Saltarelle library Firebug which implements Firebug's console API and has some more methods. Check this repo's Wiki.

@JechoJekov
Copy link
Author

This Firebug library seems like a good solution. The formatting overload methods can cause some confusion though since they are unrelated to the "String.Format" method C# developers are used to.

Still - why us it necessary to use an external class instead of adding a few methods to the built-in one? At the very minimum an overload that accept an object as an argument is necessary as having just a method that accepts a string is very limiting. Most browsers provide means to interactively inspect an object when it is printed to the console.

@nippur72
Copy link
Contributor

@JechoJekov yes best is to include it in System.Console instead of having a separate class. My intention was to extend by the use of extension methods but, to my surprise, in C# static classes can't have extension methods.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants