I was using this code in a library project using the Framework .NET 4.5 and it works fine
protected void OnPropertyChanged<TProperty>(Expression<Func<TProperty>> property)
{
if (this.IsInpcActive)
{
this.OnPropertyChanged(property.GetMemberInfo().Name);
}
}
I copy-pasted this code in a project using the .NET Frameworkwith 4.5.2 and I receive this error message:
'System.Linq.Expressions.Expression<System.Func<TProperty>>' does not contain a definition for 'GetMemberInfo' and no extension method 'GetMemberInfo' accepting a first argument of type 'System.Linq.Expressions.Expression<System.Func<TProperty>>' could be found (are you missing a using directive or an assembly reference?
As I don't really want to loose too much time, I found a plan B: extension method:
internal static class ExpressionExtensions
{
#region Methods
public static MemberInfo GetMemberInfo(this Expression expression)
{
var lambda = (LambdaExpression)expression;
MemberExpression memberExpression;
if (lambda.Body is UnaryExpression)
{
var unaryExpression = (UnaryExpression)lambda.Body;
memberExpression = (MemberExpression)unaryExpression.Operand;
}
else
memberExpression = (MemberExpression)lambda.Body;
return memberExpression.Member;
}
#endregion Methods
}
But I'm cusious: where did this method go?