LINQPad Tips and Tricks - Part 3

This is the 3rd blog post in my LINQPad Tips and Tricks series. The first two posts can be found below. If you haven't read them already, I'd highly recommend having a look through those as well as this post...

As I've already covered why LINQPad is so awesome in part one, I'm just going to jump straight into the tips...

Regular Expression Editor!

The first tip (at the time of writing) is a very new addition to LINQPad. If you press ctrl-shift-f1 , you get a built-in Regular Expression Tool! In the past I've used various different regex tools (RegexBuddy, RegExr, and RegEx101), but having this built into a tool I always have open anyway, makes this so handy.

Visually Compare two objects

If you have two instances of the same (or similar) object type, you can easily compare the values with the Util.Dif() helper method, and you'll get a nicely rendered diff making it easy to see the differences...

(screenshots taken from the author's tweet about this)

Built-in Charting support!

Previously you've been able to create charts in LINQPad by utilising 3rd-party nuget packages, or calling Util.Image with a link to a Google Chart API url (see here for an example of both). But as of the end of 2017, LINQPad now has built-in charting support with the Chart extension method...

Using F12 on the SeriesType enum (see the IlSpy tip below), we can see it supports the following chart types...

public enum SeriesType { Column, Bar, Line, Area, Point, BevelledPie, Pie, Spline, StackedBar, StackedColumn, StackedArea, StackedBar100, StackedColumn100, StackedArea100, SplineArea, Radar, Polar }

HTML Controls

In Part 2 of this series, there was a tip about "Adding Winforms or WPF controls" to the output window. With the latest update, LINQPad now has added its own set of HTML controls...

IlSpy now built-in

If you want to look at the source-code of a method you're looking at, but don't have the original source (perhaps, it's a 3rd-party library), then you can F12 into the method, and LINQPad will open ILSpy to decompile it.

Vi Mode

This tip is only really a tip if you're already a Vim user! I wanted to include it incase you were and hadn't realised that LINQPad had 'Vi mode' built-in! This was added earlier this year, and being a long-time Vi user - this made me very happy! If you're interested in learning more about Vi, I did a 20-minute lightning talk on this at .NET Oxford, which can be found here.

Use Alt-\ to list members in the current file

I'm used to using alt-\ in Resharper to get a dropdown list of all the members the current file - but I hadn't realised that LINQPad did the same until I accidentally hit the hotkey out of habit after Visual Studio! This'll give you a dialog where you can quickly jump to a class, method, or property in the current file!

'Find in Files' query

This one is less of a tip, but more an out of interest bit of LINQPad awesomeness - but if you 'find in files' with ctrl-shift-f , and search for something, LINQPad creates a new LINQ query for it!...

Play with C8's nullable reference types

Can't wait for C#8 to come out? If you enable the experimental Roslyn assembly features, then LINQPad gives you the perfect place to play! If you don't know what nullable reference types are, then see the 'Nullable Reference Types' section of my blog post about Jon Skeet's C#8 talk at the .NET Oxford user-group I run.

Browse a Database Schema programmatically

Ever need to programatically query a database schema? You'll probably say no initially, but it's surprising by how many useful use-cases this has. One simple one is just dumping out the full schema...

This is the code from that screenshot so you can copy it...

foreach (var table in Mapping.GetTables()) { (from dm in table.RowType.DataMembers where dm.DbType != null select new { dm.Name, dm.DbType, dm.Type, dm.MappedName, dm.IsPrimaryKey }).Dump(table.TableName); }

DumpLatest

I only heard about this one when it was mentioned by James World in his 'An Introduction to Reactive Extensions' talk at .NET Oxford. You can use the DumpLatest() extension method on an IObservable collection instead of the usual Dump() , and it'll watch the collection and dump out the most recent value.

The example below is taken from the built-in examples (see the 'Built-in "LINQPad Tutorials & Reference"' section below)...

// The DumpLatest extension method renders just the latest element: Observable.Interval (TimeSpan.FromSeconds (0.2)).DumpLatest(); Observable.Interval (TimeSpan.FromSeconds (0.3)).DumpLatest(); // The effect is rather like using a DumpContainer - query://../Dumping_things_that_move/DumpContainer

Built-in "LINQPad Tutorials & Reference"

As of mid-2017, there's now a fantastic reference for LINQPad built-in. There are tons of useful examples to look through. And the 'find in files' tip I mentioned above also searches these examples!

Free Syncfusion 'LINQPad Succinctly' ebook

Syncfusion has a ton of useful ebooks for free download, and they even have one on LINQPad!

Summary

I hope these tips have been useful, and a massive thanks to the author Joe Albahari for creating such an amazing tool. I use it many times daily for so many different use-cases. If it's not already in your toolbox, especially if you're a .NET developer, then it definitely should be!

Please retweet if you enjoyed this post ...