Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a LINQ Expression tree Node

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to create LINQ Expression tree nodes, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Create a LINQ Expression tree node

Once you understand the concept of LINQ Expression tree, you can discuss how to create nodes in this tree. LINQ Expression tree nodes are typically created through the factory method on the System.Linq.Expression.Expression class. Includes some of the following methods:

Add: BinaryExpression AddChecked: BinaryExpression And: BinaryExpression AndAlso: BinaryExpression ArrayIndex: BinaryExpression ArrayLength: UnaryExpression Call: MethodCallExpression Coalesce: BinaryExpression Condition: ConditionalExpression Constant: ConstantExpression Convert: UnaryExpression ConvertChecked: UnaryExpression Divide: BinaryExpression Equal: BinaryExpression ExclusiveOr: BinaryExpression Field: MemberExpression GreaterThan: BinaryExpression GreaterThanOrEqual: BinaryExpression Invoke: InvocationExpression Lambda: Expression LeftShift: BinaryExpression LessThan: BinaryExpression LessThanOrEqual: BinaryExpression ListInit: ListInitExpression MakeBinary: BinaryExpression MakeMemberAccess: MemberExpression MakeUnary: UnaryExpression MemberInit : MemberInitExpression Modulo: BinaryExpression Multiply: BinaryExpression MultiplyChecked: BinaryExpression Negate: UnaryExpression NegateChecked: UnaryExpression New: NewExpression NewArrayBounds: NewArrayExpression NewArrayInit: NewArrayExpression Not: UnaryExpression NotEqual: BinaryExpression Or: BinaryExpression OrElse: BinaryExpression Parameter : ParameterExpression Power: BinaryExpression Property: MemberExpression PropertyOrField: MemberExpression Quote: UnaryExpression RightShift: BinaryExpression Subtract: BinaryExpression SubtractChecked: BinaryExpression TypeAs: UnaryExpression TypeIs: TypeBinaryExpression UnaryPlus: UnaryExpression

Each name in the above list actually corresponds to a set of overloads with different parameters, but the type of the return value is the same. The meaning of the expressions generated by these factory methods should be said to be intuitive and not specifically introduced. You should be particularly familiar with these names if you often deal with compilers.

The hierarchy of the classes corresponding to these factory methods is:

System.Object System.Linq.Expressions.Expression System.Linq.Expressions.BinaryExpression System.Linq.Expressions.ConditionalExpression System.Linq.Expressions.ConstantExpression System.Linq.Expressions.InvocationExpression System.Linq.Expressions.LambdaExpression System.Linq.Expressions.Expression System.Linq.Expressions.MemberExpression System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.NewExpression System.Linq.Expressions.NewArrayExpression System.Linq.Expressions.MemberInitExpression System.Linq.Expressions.ListInitExpression System.Linq.Expressions.ParameterExpression System.Linq.Expressions.TypeBinaryExpression System.Linq.Expressions.UnaryExpression

Observation shows that classes in the LINQ Expression tree node can only be used to represent expressions, not "larger" syntax structures, such as assignment expressions, general statements, and so on. This is an important limitation of LINQ v1, which is why the specification of C # 3.0 explicitly states that the body of a lambda expression that can be assigned to an Expressin type can only be an expression, not a code block-- a code block cannot be represented by Expression tree in LINQ v1. It is also worth noting that LINQ Expression tree is essentially a statically typed tree-- the types represented by all nodes can be determined at compile time.

These are all the contents of the article "how to create LINQ Expression tree nodes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report