프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / Markus.Mvvm.ToolKit / NotificationControl.cs @ df2e7646

이력 | 보기 | 이력해설 | 다운로드 (969 Bytes)

1
using System;
2
using System.ComponentModel;
3
using System.Linq.Expressions;
4

    
5
namespace Markus.Mvvm.ToolKit
6
{
7
    public abstract class Notify : INotifyPropertyChanged
8
    {
9
        public event PropertyChangedEventHandler PropertyChanged;
10
        protected virtual void OnPropertyChanged(Expression<Func<object>> propertyExpression)
11
        {
12
            PropertyChangedEventHandler handler = PropertyChanged;
13
            if (handler != null) handler(this, new PropertyChangedEventArgs(GetPropertyName(propertyExpression)));
14
        }
15

    
16
        private string GetPropertyName(Expression<Func<object>> propertyExpression)
17
        {
18
            var unaryExpression = propertyExpression.Body as UnaryExpression;
19
            var memberExpression = unaryExpression == null ? (MemberExpression)propertyExpression.Body : (MemberExpression)unaryExpression.Operand;
20
            var propertyName = memberExpression.Member.Name;
21
            return propertyName;
22
        }
23
    }
24
}
클립보드 이미지 추가 (최대 크기: 500 MB)