Should I disassemble ExpressionTree?

I am currently reading the MSDN Walkthrough: Creating an IQueryable LInQ Provider , and there is a lot of use ExpressionVisitor.

I wonder is this an expensive operation?

How expensive is it like a reflection?

+5
source share
1 answer

No, it should be pretty cheap to traverse the expression tree with ExpressionVisitor.

No runtime is needed to parse the expression tree. The compiler does all the work of turning an expression into a tree of objects at compile time. There are not many reflections at runtime when the objects in question are created in memory. When you see a method call, for example:

SomeMethod(Foo x => x.Property);

SomeMethod Expression typed, IL, , - :

SomeMethod(new MemberExpression {
  Expression = new ParameterExpression("x", typeof(Foo)),
  Member = typeof(Foo).GetProperty("Property")
});

IL Microsoft. (, MemberExpressions PropertyInfo), .

, , (, Visual Studio ) , .

+1

All Articles