Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In LINQPad, the results has special styling for NULL. How can I apply that to boolean values or other values?

Tags:

linqpad

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.

null values are styled differently

like image 514
MADCookie Avatar asked Oct 27 '11 21:10

MADCookie


2 Answers

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.

like image 121
Joe Albahari Avatar answered Nov 17 '22 06:11

Joe Albahari


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;
    }
}
like image 3
AuthorProxy Avatar answered Nov 17 '22 08:11

AuthorProxy