Does anyone have a complete list of LINQPad extension methods and methods, such as
.Dump() SubmitChanges()
Much appreciated!
Does anyone have a complete list of LINQPad extension methods and methods, such as
.Dump() SubmitChanges()
Much appreciated!
LINQPad defines two extension methods (in LINQPad.Extensions), namely Dump() and Disassemble(). Dump() writes to the output window using LINQPad's output formatter and is overloaded to let you specify a heading:
typeof (int).Assembly.Dump ();
typeof (int).Assembly.Dump ("mscorlib");
You can also specify a maximum recursion depth to override the default of 5 levels:
typeof (int).Assembly.Dump (1); // Dump just one level deep
typeof (int).Assembly.Dump (7); // Dump 7 levels deep
typeof (int).Assembly.Dump ("mscorlib", 7); // Dump 7 levels deep with heading
Disassemble() disassembles any method to IL, returning the output in a string:
typeof (Uri).GetMethod ("GetHashCode").Disassemble().Dump();
In addition to those two extension methods, there are some useful static methods in LINQPad.Util. These are documented in autocompletion, and include:
LINQPad also provides the HyperLinq class. This has two purposes: the first is to display ordinary hyperlinks:
new Hyperlinq ("www.linqpad.net").Dump();
new Hyperlinq ("www.linqpad.net", "Web site").Dump();
new Hyperlinq ("mailto:[email protected]", "Email").Dump();
You can combine this with Util.HorizontalRun:
Util.HorizontalRun (true,
"Check out",
new Hyperlinq ("http://stackoverflow.com", "this site"),
"for answers to programming questions.").Dump();
Result:
Check out this site for answers to programming questions.
The second purpose of HyperLinq is to dynamically build queries:
// Dynamically build simple expression:
new Hyperlinq (QueryLanguage.Expression, "123 * 234").Dump();
// Dynamically build query:
new Hyperlinq (QueryLanguage.Expression, @"from c in Customers
where c.Name.Length > 3
select c.Name", "Click to run!").Dump();
You can also set up your own extensions methods for use in LINQPad. The first step is to write and test your extension methods - you can do that in LINQPad by setting the query language to 'Program':
void Main()
{
"hello".Pascal().Dump();
}
public static class MyExtensions
{
public static string Pascal (this string s)
{
return char.ToLower (s[0]) + s.Substring(1);
}
}
The next step is to paste those extensions methods into a class library in Visual Studio. After compiling your library, go back to LINQPad and press F4 to add a reference to that library - and click Use as default for new queries.
Dump is a global extension method and SubmitChanges comes from the DataContext object which is a System.Data.Linq.DataContext object.
LP adds only Dump and Disassemble as far as I'm aware. Though I would highly recommend opening it in Reflector to see what else is there that can be used. One of the more interesting things is the LINQPad.Util namespace which has some goodies used by LINQPad internally.