LINQPad [扩展] 方法 [英] LINQPad [extension] methods

查看:22
本文介绍了LINQPad [扩展] 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有LINQPad扩展方法和方法的完整列表,比如

Does anyone have a complete list of LINQPad extension methods and methods, such as

.Dump()

SubmitChanges()

推荐答案

LINQPad 定义了两个扩展方法(在 LINQPad.Extensions 中),分别是 Dump()Disassemble().Dump() 使用 LINQPad 的输出格式化程序写入输出窗口,并被重载以让您指定标题:

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");

您还可以指定最大递归深度来覆盖默认的 5 个级别:

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() 将任何方法反汇编为 IL,以字符串形式返回输出:

Disassemble() disassembles any method to IL, returning the output in a string:

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

除了这两个扩展方法之外,LINQPad.Util 中还有一些有用的静态方法.这些记录在自动完成中,包括:

In addition to those two extension methods, there are some useful static methods in LINQPad.Util. These are documented in autocompletion, and include:

  • Cmd - 执行 shell 命令或外部程序
  • CreateXhtmlWriter - 创建一个使用 LINQPad 的 Dump() 格式化程序的文本编写器
  • SqlOutputWriter - 返回写入 SQL 输出窗口的文本编写器
  • GetMyQueriesGetSamples - 返回代表您保存的查询/样本的对象集合(例如,使用 Edit | Search All 执行搜索)
  • 突出显示 - 包裹一个对象,使其在倾倒时以黄色突出显示
  • Horizo​​ntalRun - 让您在同一行上转储一系列对象
  • Cmd - executes a shell command or external program
  • CreateXhtmlWriter - creates a text writer that uses LINQPad's Dump() formatter
  • SqlOutputWriter - returns the text writer that writes to the SQL output window
  • GetMyQueries, GetSamples - returns a collection of objects representing your saved queries / samples (for an example, execute a search using Edit | Search All)
  • Highlight - wraps an object so that it will highlight in yellow when Dumped
  • HorizontalRun - lets you Dump a series of objects on the same line

LINQPad 还提供了 HyperLinq 类.这有两个目的:第一个是显示普通的超链接:

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:user@domain.com", "Email").Dump();

您可以将其与 Util.Horizo​​ntalRun 结合使用:

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();

结果:

查看本网站以获得编程问题的答案.

Check out this site for answers to programming questions.

HyperLinq 的第二个目的是动态构建查询:

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();

您也可以在 LINQPad 中编写自己的扩展方法.转到我的查询"并单击名为我的扩展"的查询.所有查询都可以访问此处定义的任何类型/方法:

You can also write your own extension methods in LINQPad. Go to 'My Queries' and click the query called 'My Extensions'. Any types/methods that define here are accessible to all queries:

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

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

在 4.46(.02) 引入了新的类和方法:

In 4.46(.02) new classes and methods have been introduced:

  • DumpContainer(类)
  • OnDemand(扩展方法)
  • Util.ProgressBar(类)

此外,Hyperlinq 类现在支持 Action 委托当您单击链接时将调用该方法,让您可以在代码中对其做出反应,而不仅仅是链接到外部网页.

Additionally, the Hyperlinq class now supports an Action delegate that will be called when you click the link, allowing you to react to it in code and not just link to external webpages.

DumpContainer 是一个类,用于将一个块添加到输出窗口中,可以替换其内容.

DumpContainer is a class that adds a block into the output window that can have its contents replaced.

注意!记得在适当的位置.Dump()DumpContainer本身.

NOTE! Remember to .Dump() the DumpContainer itself in the appropriate spot.

使用:

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

OnDemand 是一个扩展方法,它不会将其参数的内容输出到输出窗口,而是添加一个可点击的链接,点击时会将链接替换为 .Dump()ed 参数的内容.这对于有时需要昂贵或占用大量空间的数据结构非常有用.

OnDemand is an extension method that will not output the contents of its parameter to the output window, but instead add a clickable link, that when clicked will replace the link with the .Dump()ed contents of the parameter. This is great for sometimes-needed data structures that is costly or takes up a lot of space.

注意!记得在适当的位置.Dump()调用OnDemand的结果.

NOTE! Remember to .Dump() the results of calling OnDemand in the appropriate spot.

使用:

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

Util.ProgressBar 是一个可以在输出窗口内显示图形进度条的类,可以随着代码的移动而改变.

Util.ProgressBar is a class that can show a graphical progressbar inside the output window, that can be changed as the code moves on.

注意!记得在适当的位置.Dump() Util.ProgressBar 对象.

NOTE! Remember to .Dump() the Util.ProgressBar object in the appropriate spot.

使用:

var pb = new Util.ProgressBar("Analyzing data");
pb.Dump();
for (int index = 0; index <= 100; index++)
{
    pb.Percent = index;
    Thread.Sleep(100);
}

这篇关于LINQPad [扩展] 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆