markus / ConvertService / ServiceBase / Markus.Mvvm.ToolKit / Notification.cs @ 45f9a2ad
이력 | 보기 | 이력해설 | 다운로드 (971 Bytes)
1 | 53c9637d | taeseongkim | using System; |
---|---|---|---|
2 | using System.ComponentModel; |
||
3 | using System.Linq.Expressions; |
||
4 | |||
5 | 45f9a2ad | taeseongkim | namespace Markus.Mvvm.ToolKit |
6 | 53c9637d | taeseongkim | { |
7 | public class NotifyExpectation : 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 | } |