2014-01-21 2 views
0

OnPropertyChanged 이벤트를 가져 와서 수정 된 클래스로 표시 할 수 있습니다.PostSharp NotifyPropertyChanged를 사용하여 OnPropertyChanged 이벤트에 연결하는 방법

[NotifyPropertyChanged]  
Public Class Employee 
{ 
    private bool hasChange;  
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    private static void OnPropertyChanged(object sender, PropertyChangedEventArgs e) 
    { 
     hasChange = true; 
    } 
} 

OnPropertyChanged 가장 가능성이 잘못 그러나 희망 당신은 내가 뭘하려고 오전의 아이디어를 얻을입니까?

감사합니다,

제임스

답변

1

당신은 PostSharp에 의해 생성 된 것과 동일한 서명으로 자신의 OnPropertyChanged 방법을 제공해야합니다. 결과적으로 PostSharp는 메소드를 생성하지 않고 대신 구현을 사용합니다. 이것은 또한 메서드에서 이벤트를 직접 발생시켜야 함을 의미합니다.

[NotifyPropertyChanged]  
public class Employee : INotifyPropertyChanged 
{ 
    private bool hasChange;  
    public string FirstName { get; set; } 
    public string LastName { get; set; } 


    public event PropertyChangedEventHandler PropertyChanged; 

    protected void OnPropertyChanged(string propertyName) 
    { 
     hasChange = true; 

     PropertyChangedEventHandler handler = this.PropertyChanged; 
     if (handler != null) 
     { 
      handler(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 
+0

내가 Postsharp를 사용하고 있다면, Postsharp의 * OnPropertyChanged * 메서드를 재정의하려면이 방법이 괜찮습니까? – Zeeshan

+1

예, PostSharp는이 경우 * OnPropertyChanged * 구현을 인식하고 사용합니다. – AlexD

+0

필자의 경우, OnPropertyChange *를 구현해야하는 30 개 이상의 모델이있다. (** 그러나 ** 나는 postsharp의 OnPropertyCahnged에 대한 내 자신의 구현을 원한다.) 이 시나리오에서 PostSharp를 활용하는 시나리오를 제안 해 주시겠습니까? 내 말은, PostSharp의 OnPropertyChanged를 재정의하는 방법입니까? 30 가지 모델을 모두 구현할 필요가 없습니다. (나는 처음으로 알림 내용을 다루고있다.) – Zeeshan