What does Expression.Quote() do that Expression.Constant() can’t already do?

后端 未结 5 844
执笔经年
执笔经年 2020-12-04 05:51

Note: I am aware of the earlier question “What is the purpose of LINQ\'s Expression.Quote method?”, but if you read on you will see that it doesn’t answer m

5条回答
  •  鱼传尺愫
    2020-12-04 06:40

    I believe it is more like given:

    Expression>> f = () => () => 2;
    

    Your tree is Expression.Lambda(Expression.Lambda) and f represents the Expression Tree for a lambda that returns a Func that returns 2.

    But if what you wanted was a lambda that returns the Expression Tree for a lambda that returns 2, then you need:

    Expression>>> f = () => () => 2;
    

    And now your tree is Expression.Lambda(Expression.Quote(Expression.Lambda)) and f represents the Expression Tree for a lambda that returns an Expression> that is the Expression Tree for a Func that returns 2.

提交回复
热议问题