is there any way in .Net 2.0 to retrieve a property name from delegate?:
i => i.Name
When I call:
var property = MyMethod(i => i.Name);
I want MyMethod to return string “Name”. So the value of ‘property’ should be “Name”.
In .Net 3.5 there is simply way to do that (Expression Tree), but I have to use 2.0 Framework only.
Chris
In .NET 2.0 you’d have to get the target method from the body, call
MethodBase.GetMethodBodyand then parse the IL. This would not be an easy task, I suspect.One option would be to use the Mono expression tree in their
System.Coreimplementation against .NET 2.0, but still compile with a C# 3 compiler. I have heard reports that this works fine, but it’s a bit of a drastic workaround.