views:

117

answers:

1

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);
 }

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

+1  A: 

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.

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.

Marcelo Cantos
Is there a good series of articles that can walk me through all this?
bitbonk
This [article](http://www.infoq.com/articles/expression-compiler) might help.
Marcelo Cantos