這是非常簡單的獲得方法調用者,甚至通過使用編譯器服務中獲得的屬性名稱的變化,如:Get方法調用者FOM集「功能」
public class EmployeeVM:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName=null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
// The compiler converts the above line to:
// RaisePropertyChanged ("Name");
}
}
private string _phone;
public string Phone
{
get { return _phone; }
set
{
_phone = value;
OnPropertyChanged();
// The compiler converts the above line to:
// RaisePropertyChanged ("Phone");
}
}
}
但有可能得到來自set內部的「set」函數的調用者?我不知道你是如何在該範圍內進行語法定義的。 AKA,誰打電話=?
C#5添加了來電信息。 http://blogs.msdn.com/b/mvpawardprogram/archive/2012/03/26/introduction-of-new-features-in-c-5-0.aspx – lukegravitt