本文介绍了拉姆达EX pression基于反射与正常反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正常反射和反射之间的区别,可以用拉姆达EX pressions完成像这样的(拍摄形式建立自己的MVVM ):

What is the difference between normal reflection and the reflection that can be done with lambda expressions such as this (taken form build your own MVVM):

public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
{
    var lambda = (LambdaExpression)property;
    MemberExpression memberExpression;
    if (lambda.Body is UnaryExpression)
    {
        var unaryExpression = (UnaryExpression)lambda.Body;
        memberExpression = (MemberExpression)unaryExpression.Operand;
    }
    else memberExpression = (MemberExpression)lambda.Body;
    NotifyOfPropertyChange(memberExpression.Member.Name);
 }

只是在内部使用的普通的反射API拉姆达基于反射?还是这东西显著不同。疗法性能比较有什么区别?

Is the lambda based reflection just using the normal reflection APIs internally? Or is this something significantly different. What is ther perfomance difference?

推荐答案

反射目标集,类和接口的结构。它可以访问类的定义,方法签名,类型信息,等等。它不提供访问方法的code,无论是在抽象语法树(AST)或字节code组成。

Reflection targets assembly, class and interface structure. It gives access to class definitions, method signatures, type information, and so on. It doesn't provide access the code of methods, either in Abstract Syntax Tree (AST) or bytecode form.

防爆pression&LT;&GT; 键入系列提供了直接访问的AST,它可以用来搜集了一块code的结构。这实际上是更接近codeDOM设施,而不是反射。

The Expression<> type family provides direct access to an AST, which can be used to glean the structure of a piece of code. This is actually much closer to the CodeDOM facility than to reflection.

这篇关于拉姆达EX pression基于反射与正常反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 01:49