System.Linq.Expressions Namespace

System.Linq.Expressions 命名空间包含一些类、接口和枚举,它们使语言级别的代码表达式能够表示为表达式目录树形式的对象。 The System.Linq.Expressions namespace contains classes, interfaces and enumerations that enable language-level code expressions to be represented as objects in the form of expression trees.

BinaryExpression

表示包含二元运算符的表达式。Represents an expression that has a binary operator.

BlockExpression

表示包含一个表达式序列的块,表达式中可定义变量。Represents a block that contains a sequence of expressions where variables can be defined.

CatchBlock

表示 try 块中的 catch 语句。Represents a catch statement in a try block.

ConditionalExpression

表示具有条件运算符的表达式。Represents an expression that has a conditional operator.

ConstantExpression

表示具有常数值的表达式。Represents an expression that has a constant value.

DebugInfoExpression

发出或清除调试信息的序列点。Emits or clears a sequence point for debug information. 这允许调试器在调试时突出显示正确的源代码。This allows the debugger to highlight the correct source code when debugging.

DefaultExpression

表示类型或空表达式的默认值。Represents the default value of a type or an empty expression.

DynamicExpression

表示动态操作。Represents a dynamic operation.

DynamicExpressionVisitor

表示动态表达式树的访问者或重写者。Represents a visitor or rewriter for dynamic expression trees.

ElementInit

表示 IEnumerable 集合的单个元素的初始值设定项。Represents an initializer for a single element of an IEnumerable collection.

Expression

提供一种基类,表示表达式树节点的类派生自该基类。Provides the base class from which the classes that represent expression tree nodes are derived. 它还包含用来创建各种节点类型的 static(在 Visual Basic 中为 Shared)工厂方法。It also contains static (Shared in Visual Basic) factory methods to create the various node types. 这是一个 abstract 类。This is an abstract class.

Expression<TDelegate>

以表达式目录树的形式将强类型 lambda 表达式表示为数据结构。Represents a strongly typed lambda expression as a data structure in the form of an expression tree. 此类不能被继承。This class cannot be inherited.

ExpressionVisitor

表示表达式树的访问者或重写者。Represents a visitor or rewriter for expression trees.

GotoExpression

表示无条件跳转。Represents an unconditional jump. 这包括 return 语句、break 和 continue 语句以及其他跳转。This includes return statements, break and continue statements, and other jumps.

IndexExpression

表示编制属性或数组的索引。Represents indexing a property or array.

InvocationExpression

表示将委托或 lambda 表达式应用于参数表达式列表的表达式。Represents an expression that applies a delegate or lambda expression to a list of argument expressions.

LabelExpression

表示一个标签,可以将该标签放置在任何 Expression 上下文中。Represents a label, which can be put in any Expression context. 如果已跳转到该标签,则它将获取由对应的 GotoExpression 提供的值。If it is jumped to, it will get the value provided by the corresponding GotoExpression. 否则,它接收 DefaultValue 中的值。Otherwise, it receives the value in DefaultValue. 如果 Type 等于 System.Void,则不应提供值。If the Type equals System.Void, no value should be provided.

LabelTarget

用于表示 GotoExpression 的目标。Used to represent the target of a GotoExpression.

LambdaExpression

描述一个 lambda 表达式。Describes a lambda expression. 这将捕获与 .NET 方法体类似的代码块。This captures a block of code that is similar to a .NET method body.

ListInitExpression

表示包含集合初始值设定项的构造函数调用。Represents a constructor call that has a collection initializer.

LoopExpression

表示无限循环。Represents an infinite loop. 可以使用“break”退出它。It can be exited with "break".

MemberAssignment

表示针对对象的字段或属性的赋值运算。Represents assignment operation for a field or property of an object.

MemberBinding

提供一种基类,该基类派生表示绑定的类,这些绑定用于初始化新创建对象的成员。Provides the base class from which the classes that represent bindings that are used to initialize members of a newly created object derive.

MemberExpression

表示访问字段或属性。Represents accessing a field or property.

MemberInitExpression

表示调用构造函数并初始化新对象的一个或多个成员。Represents calling a constructor and initializing one or more members of the new object.

MemberListBinding

表示初始化新创建对象的集合成员的元素。Represents initializing the elements of a collection member of a newly created object.

MemberMemberBinding

表示初始化新创建对象的成员的成员。Represents initializing members of a member of a newly created object.

MethodCallExpression

表示对静态方法或实例方法的调用。Represents a call to either static or an instance method.

NewArrayExpression

表示创建新数组并可能初始化该新数组的元素。Represents creating a new array and possibly initializing the elements of the new array.

NewExpression

表示构造函数调用。Represents a constructor call.

ParameterExpression

表示命名的参数表达式。Represents a named parameter expression.

RuntimeVariablesExpression

一个为变量提供运行时读/写权限的表达式。An expression that provides runtime read/write permission for variables.

SwitchCase

表示 SwitchExpression 的一个事例。Represents one case of a SwitchExpression.

SwitchExpression

表示一个控制表达式,该表达式通过将控制传递到 SwitchCase 来处理多重选择。Represents a control expression that handles multiple selections by passing control to SwitchCase.

SymbolDocumentInfo

存储发出源文件的调试符号信息所需的信息,尤其是文件名和唯一语言标识符。Stores information necessary to emit debugging symbol information for a source file, in particular the file name and unique language identifier.

TryExpression

表示 try/catch/finally/fault 块。Represents a try/catch/finally/fault block.

TypeBinaryExpression

表示表达式和类型之间的操作。Represents an operation between an expression and a type.

UnaryExpression

表示包含一元运算符的表达式。Represents an expression that has a unary operator.

接口

IArgumentProvider

提供用于访问多个树节点(DynamicExpression、ElementInit、MethodCallExpression、InvocationExpression、NewExpression 和 IndexExpression)的参数的内部接口。Provides an internal interface for accessing the arguments of multiple tree nodes (DynamicExpression, ElementInit, MethodCallExpression, InvocationExpression, NewExpression, and IndexExpression). 不应使用此 API。You should not use this API. 由于 DLL 重构,它只能是公共的;并且仅用于内部性能优化。It is only public due to DLL refactoring and exists only for internal performance optimizations.

这能够实现两次优化,从而减少了表达式树的大小。This enables two optimizations which reduce the size of expression trees. 第一次优化可以使树节点保留在 IList <T> 上而不是 ReadOnlyCollection 上。The first enables the tree nodes to hold onto an IList<T> instead of a ReadOnlyCollection. IList <T> 可节省为每个节点分配 ReadOnlyCollection 的成本。IList<T> saves the cost of allocating the ReadOnlyCollection for each node. 第二次优化能够创建专用的子类,可保留特定数量的参数(例如,Block2、Block3、Block4)。The second enables creating specialized subclasses that hold onto a specific number of arguments (for example, Block2, Block3, Block4). 因此,这些节点避免了分配 ReadOnlyCollection 和数组以存储其元素,从而为每个节点节省了 32 个字节。Therefore, these nodes avoid allocating both a ReadOnlyCollection and an array for storing their elements, saving 32 bytes per node.

表达式树节点继续公开 ReadOnlyCollections 的原始 LINQ 属性。The expression tree nodes continue to expose the original LINQ properties of ReadOnlyCollections. 这些节点通过重复使用用于存储数组或元素(通常存储在数组中)的字段来执行此操作。The nodes do this by re-using a field for storing both the array or an element that would normally be stored in the array.

对于数组用例,集合将类型化为 IList <T>,而不是 ReadOnlyCollection <T>。For the array case, the collection is typed to IList<T> instead of ReadOnlyCollection<T>. 当最初构造该节点时,它是一个数组。When the node is initially constructed it is an array. 当编译器访问成员时,它会使用此接口。When the compiler accesses the members it uses this interface. 访问数组元素可以将数组提升为 ReadOnlyCollection。Accessing array elements promotes the array to a ReadOnlyCollection.

对于对象用例,我们会将第一个参数存储在类型为对象的字段中。For the object case we store the first argument in a field typed to object. 当最初构造该节点时,该字段将持有该表达式。When the node is initially constructed, the field holds the Expression. 编译器通过此接口访问参数,第一个参数的访问器使用 Expression.ReturnObject 返回用于处理表达式或 ReadOnlyCollection 用例的对象。The compiler accesses arguments through this interface, and the accessor for the first argument uses Expression.ReturnObject to return the object that handles the Expression or ReadOnlyCollection case. 当用户访问 ReadOnlyCollection 时,将更新对象字段以直接保留 ReadOnlyCollection。When the user accesses the ReadOnlyCollection, then the object field is updated to hold directly onto the ReadOnlyCollection.

表达式始终返回相同的 ReadOnlyCollection,这一点很重要。It is important that the Expressions consistently return the same ReadOnlyCollection. 否则,将中断重写树查看器。Otherwise, the re-writer tree walker will break. 从 LINQ v1 返回不同的 ReadOnlyCollections 形成相同的表达式节点,这是一个重大突破。It is a breaking change from LINQ v1 to return different ReadOnlyCollections form the same Expression node. 当前用户可以依赖对象标识来区分该节点是否已更改。Currently users can rely on object identity to tell if the node has changed. 在重载字段中存储 ReadOnlyCollection 既可减少内存使用量,又可保持公共 API 兼容性。Storing the ReadOnlyCollection in an overloaded field both reduces memory usage and maintains compatibility for the public API.

IDynamicExpression

提供用于访问 DynamicExpression 树节点的参数及 CallSite 和重写功能的内部接口。Provides an internal interface for accessing the arguments of DynamicExpression tree nodes as well as CallSite and Rewriting functionality. 不应使用此 API。You should not use this API. 由于 DLL 重构,它只能是公共的;并且仅用于内部性能优化。It is only public due to DLL refactoring and exists only for internal performance optimizations.

枚举

ExpressionType

描述表达式目录树的节点的节点类型。Describes the node types for the nodes of an expression tree.

GotoExpressionKind

指定此 GotoExpression 表示的跳转种类。Specifies what kind of jump this GotoExpression represents.

MemberBindingType

描述 MemberInitExpression 对象中使用的绑定类型。Describes the binding types that are used in MemberInitExpression objects.

注解

抽象类Expression提供用于映射到模型的表达式树类层次结构的根。The abstract class Expression provides the root of a class hierarchy used to model expression trees.

从派生此命名空间中的类Expression,例如MemberExpressionParameterExpression,用于表示表达式树中的节点。The classes in this namespace that derive from Expression, for example MemberExpression and ParameterExpression, are used to represent nodes in an expression tree. Expression类包含static(Shared在 Visual Basic 中) 创建表达式树节点的各种类型的工厂方法。The Expression class contains static (Shared in Visual Basic) factory methods to create expression tree nodes of the various types.

枚举类型ExpressionType指定唯一的节点类型。The enumeration type ExpressionType specifies the unique node types.