LINQPad如何引用其他类,例如LINQ in Action示例中的Books

Edw*_*uay 64 c# linq linq-to-objects linqpad

我正在使用LINQPad在我正在构建的应用程序中创建LINQ查询.

我注意到在下载的LINQ in Action示例中,例如示例4.04,intellisense显示了一个类"Books",但我在LINQPad工具中看不到任何引用或" using "语句,这里是示例:

List<Book> books = new List<Book>() {
  new Book { Title="LINQ in Action" },
  new Book { Title="LINQ for Fun" },
  new Book { Title="Extreme LINQ" } };

var titles =
  books
    .Where(book => book.Title.Contains("Action"))
    .Select(book => book.Title);

titles.Dump();
Run Code Online (Sandbox Code Playgroud)

在"LinqBooks.Common中,Business Objects,Book.linq "是类似乎定义的地方:

public class Book
{
  public IEnumerable<Author> Authors {get; set;}
  public String Isbn {get; set;}
  public String Notes {get; set;}
  public Int32 PageCount {get; set;}
  public Decimal Price {get; set;}
  public DateTime PublicationDate {get; set;}
  public Publisher Publisher {get; set;}
  public IEnumerable<Review> Reviews {get; set;}
  public Subject Subject {get; set;}
  public String Summary {get; set;}
  public String Title {get; set;}
  public String Test {get; set;}

  public override String ToString()
  {
    return Title;
  }
}
Run Code Online (Sandbox Code Playgroud)

但这是如何工作的,以便我可以复制我的类并使用LINQPad快速构建LINQ语句,然后我可以将其复制回我的应用程序?

Win*_*ith 105

如果右键单击LINQPad中的代码编辑器并选择"高级查询属性",则会出现两个对话框:"其他引用"和"其他命名空间导入".

1)在" 其他参考"中,选择" 添加",然后单击" 浏览"并导航到自定义装配.

2)然后,在Additional Namespace Imports中,键入要从该程序集导入的名称空间.


And*_*are 10

LINQPad允许您通过" 高级查询属性"对话框引用自定义程序集,可以通过按下打开该对话框F4.