In LINQPad, results have a special style for NULL. How can I apply this to booleans or other values?

I would like to be able to create different return values, similar to how LINQPad NULL styles are italicized in green text. In particular, I would like the Boolean style of the values ​​TRUE and FALSE in different ways, like blue and red.

null values ​​are styled differently

+6
source share
2 answers

This cannot be done using the built-in style editor. However, you can write an extension method that you call 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 in the VS project and copy the DLL into the LINQPad plugins folder, it will be automatically available for all requests.

EDIT: Now you can define this method in the "My Extensions" query, rather than creating a project in VS.

+8
source

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; } } 
+3
source

Source: https://habr.com/ru/post/900246/


All Articles