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.
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.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With