2

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there a good series of articles that can walk me through all this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.