I would like to be able to style different return values similar to how LINQPad styles NULL as italic green text. Specifically, I would like to style Boolean values TRUE and FALSE differently like blue and red.
Asked
Active
Viewed 1,546 times
2 Answers
9
This can't be done through the built-in stylesheet editor. However you could write an extension method that you invoke as follows:
void Main()
{
// AdventureWorks
Contacts.Select (c => new { c.FirstName, c.LastName, NameStyle = c.NameStyle.RedBlue() }).Dump();
}
static class Extensions
{
public static object RedBlue (this bool value)
{
string c = value ? "Blue" : "Red";
return Util.RawHtml ("<span style='color:" + c + "'>" + value + "</span>");
}
}
If you put the extension method into a VS project and copy the DLL into the LINQPad plugins folder, it will be automatically available to all queries.
EDIT: You can now define that method in the 'My Extensions' query rather than having to create a project in VS.

Joe Albahari
- 30,118
- 7
- 80
- 91
-
The extensions class work wonderfully in LINQPad when I add it in my query, but compiling it to a separate DLL does not work. LINQPad is saying it doesn't have a definition for the extension. Perhaps there is something I missed when creating a class in VS. I don't want to take your time on this as I can wait for the final release with plugin baked in. – MADCookie Oct 28 '11 at 19:40
-
1I presume you've checked the obvious things... the class is public and the namespace is imported (or more easily, you can define it the top-level namespace). Are you referencing the DLL manually from LINQPad or dropping it into the plugins folder? – Joe Albahari Oct 29 '11 at 02:47
-
Thank you for checking the obvious! I just didn't set the class public!! Oops. Thank you for your help and this great tip on enhancing the output. – MADCookie Oct 31 '11 at 16:57
3
I have success with this code block in MyExtensions sketch:
void Main()
{
(!(true.Dump())).Dump();
}
public static class MyExtensions
{
public static bool Dump (this bool value)
{
string c = value ? "Blue" : "Red";
Util.RawHtml ("<span style='color:" + c + "'>" + value + "</span>").Dump();
return value;
}
}

AuthorProxy
- 7,946
- 3
- 27
- 40