How RaisePropertyChanged finds out the property name?

前端 未结 1 761
北恋
北恋 2021-02-19 20:05

There is one overload of this method in NotificationObject :-

protected void RaisePropertyChanged(Expression> propertyE         


        
1条回答
  •  野的像风
    2021-02-19 20:27

    An Expression represents the abstract syntax tree of the lambda expression. So you just have to analyze this syntax tree to find out the property name:

    protected void RaisePropertyChanged(Expression> propertyExpression)
    {
        var memberExpr = propertyExpression.Body as MemberExpression;
        if (memberExpr == null)
            throw new ArgumentException("propertyExpression should represent access to a member");
        string memberName = memberExpr.Member.Name;
        RaisePropertyChanged(memberName);
    }
    

    0 讨论(0)
提交回复
热议问题