[extension] methods for LINQPad

.net c# entity-framework linqpad linq-to-sql

Question

Exists a comprehensive collection of LINQPad extension methods and techniques, including as

.Dump()

SubmitChanges()
1
138
1/16/2017 3:07:25 PM

Accepted Answer

In LINQPad.Extensions, LINQPad defines two extension methods, namelyDump() and Disassemble() . Dump() The output formatter for LINQPad writes to the output window and is overloaded to allow you to define a heading:

typeof (int).Assembly.Dump ();
typeof (int).Assembly.Dump ("mscorlib");

The default recursion depth is five levels, but you may change it by specifying a higher number:

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() breaks down every procedure toIL , delivering the result as a string:

typeof (Uri).GetMethod ("GetHashCode").Disassemble().Dump();

In addition to the two extension methods, LINQPad.Util also includes several helpful static methods. These are listed in autocomplete and consist of:

  • Executes a shell command or an external program: Cmd
  • Creates a text writer using LINQPad's Dump() formatter with the command CreateXhtmlWriter.
  • The text writer that writes to the SQL output window is returned by the command SqlOutputWriter.
  • A collection of objects containing your stored queries or samples is returned by the functions GetMyQueries and GetSamples (for an example, do a search using Edit | Search All).
  • Wraps an item in Highlight so that it will highlight in yellow when dumped.
  • You may Dump a number of objects on the same line with the code HorizontalRun.

HyperLinq is another class offered by LINQPad. This serves two objectives: the first step is to show regular hyperlinks:

new Hyperlinq ("www.linqpad.net").Dump();
new Hyperlinq ("www.linqpad.net", "Web site").Dump();
new Hyperlinq ("mailto:user@domain.com", "Email").Dump();

You may pair this withUtil.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.

HyperLinq's second objective is to dynamically construct 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();

In LINQPad, you can also create your own extension methods. Go to "My Queries" and choose the "My Extensions" query. All queries may use any types or methods defined here:

void Main()
{
  "hello".Pascal().Dump();  
}

public static class MyExtensions
{
  public static string Pascal (this string s)
  {
    return char.ToLower (s[0]) + s.Substring(1);
  }
}

There are new seminars and techniques available. in 4.46(.02)

  • DumpContainer (class)
  • OnDemand (extension method)
  • Util.ProgressBar (class)

The Hyperlinq class now supports an additional Action delegate that is called when the link is clicked, enabling you to respond to it in code rather to merely linking to other websites.

DumpContainer is a class that includes a block in the output window whose contents may be changed.

NOTE! Recall to.Dump() the DumpContainer itself at the proper place.

To use:

var dc = new DumpContainer();
dc.Content = "Test";
// further down in the code
dc.Content = "Another test";

OnDemand is an extension method that, instead of adding the parameter's contents to the output window, adds a clickable link that, when clicked, replaces the existing link with the parameter's content..Dump() The parameter's contents were ed. This is excellent for expensive or large-scale data structures that are sometimes required.

NOTE! Recall to.Dump() what happens when you callOnDemand at the proper place.

To apply it:

Customers.OnDemand("Customers").Dump(); // description is optional

Util.ProgressBar is a class that can display a progress bar that changes while the code is run within the output window.

NOTE! Recall to.Dump() the right location for the Util.ProgressBar object.

To apply it:

var pb = new Util.ProgressBar("Analyzing data");
pb.Dump();
for (int index = 0; index <= 100; index++)
{
    pb.Percent = index;
    Thread.Sleep(100);
}
247
12/9/2015 9:13:08 PM

Popular Answer

SubmitChanges originates from the DataContext object, which is a System, and Dump is a global extension function. Data.Linq. Object DataContext.

I believe that LP simply adds Dump and Disassemble. However, I strongly advise opening it in Reflector to see what else could be useful. The LINQPad is one of the most intriguing features. The Util namespace contains various useful items that LINQPad uses internally.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow