How this code works for handling INotifyPropertyChanged?

An expression tree is an object-oriented representation of an expression at runtime. The C# compiler can automatically write a limited subset of expressions as Expression instances, via a lambda - i. E Func anonMethod = () => "abc"; // this is a delegate Expression expression = () => "abc"; // this is an expression The above will have a ConstantExpression your example will have a ConstantExpression that captures this and a MemberExpression that wraps that constant ( this ) and the member ( Name ).

Then at runtime, it locates the MemberExpression which has a MemberInfo which has a Name It could even have a ConstantExpression to a capture class a MemberExpression to this (as a field on the capture-class), and then a MemberExpression to Name The difference is subtle, but an expression can be pulled apart and inspected at runtime - which is critical for LINQ. However: while the compiler can write these, they are not free to inspect; they have cost too IMO, perhaps stick with: public string Name { get { return _name; } set { SomeSimpleNotifyMethod(ref _name, value, this, "Name"; } } this is simpler and faster (obviously, changing the method to take a string that it passes to the event).

An expression tree is an object-oriented representation of an expression at runtime. The C# compiler can automatically write a limited subset of expressions as Expression instances, via a lambda - i.e. Func anonMethod = () => "abc"; // this is a delegate Expression expression = () => "abc"; // this is an expression The above will have a ConstantExpression; your example will have a ConstantExpression that captures this and a MemberExpression that wraps that constant (this) and the member (.Name).

Then at runtime, it locates the MemberExpression, which has a MemberInfo, which has a Name. It could even have a ConstantExpression to a capture class, a MemberExpression to this (as a field on the capture-class), and then a MemberExpression to .Name. The difference is subtle, but an expression can be pulled apart and inspected at runtime - which is critical for LINQ.

However: while the compiler can write these, they are not free to inspect; they have cost too. IMO, perhaps stick with: public string Name { get { return _name; } set { SomeSimpleNotifyMethod(ref _name, value, this, "Name"; } } this is simpler and faster (obviously, changing the method to take a string that it passes to the event).

Thanks. You are a great developer. I don't understand this.

This in this example point to PropertyChangedEventHandler and how lamda expression wrap this and Name together? Is MemberExpression is delegate(lambda) part of Expression Tree? Why in line 7 got body of Expression and again in line 17 get Expressoin of body?

Sorry but it's to comlecated for me. – Nima Jul 26 at 11:26 1 @Nima no, the delegate is not part of the lambda; that was for contrast only. The bit on line 7 is identifying that the expression is actually a member-access; the bit on line 17 is looking for the object (this in my discussion above); rather than understand the entire tree they've chosen to do a Compile()/DynamicInvoke(), which is, btw, very slow (relatively speaking).

Again, I don't recommend that code. – Marc Gravell? Jul 26 at 11:31 you say : The above will have a ConstantExpression.

If so why in line 17 convert body to ConstantExpression? – Nima Jul 26 at 11:32 @Nima it doesn't; the MemberExpression is, like in C#, a combination of an object and a member, i.e. In C# this.Name; here, the target object is specified as an Expression (just like in C# really, i.e.

{some compound expression}. Name). It is testing that to see if it is constant.

– Marc Gravell? Jul 26 at 11:39 1 @Nima no, not really.It is a bit of a niche; I've blogged about it a bit, etc, but nothing major. To be honest, if you play with it a little while it makes a lot more sense ;p It is wicked confusing initially - don't worry, that is normal.

You aren't going mad - this stuff is crazy. – Marc Gravell? Jul 26 at 21:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions