1
編輯輸入錯誤的屬性名稱,例如Impleneting的通用接口通用功能
假設我們有這樣
public interface IBase {}
public interface IItf_1: IBase {}
public interface IItf_2: IBase {}
public interface IItf_3: IBase {}
public interface IInterfaceHolder<T>: IBase, INotifyPropertyChanged {
// Changes to this property caused raise of the PropertyChanged event
bool Checked { get; set; }
T Item { get; }
}
public interface ISomeFunnyInterface: INotifyPropertyChanged {
IEnumerable<IInterfaceHolder<IItf_1>> Collection_1 { get; }
IEnumerable<IInterfaceHolder<IItf_2>> Collection_2 { get; }
IEnumerable<IInterfaceHolder<IItf_3>> Collection_3 { get; }
}
的想法是隧道的PropertyChanged從每個Checked屬性PropertyChaned接口從ISomeFunnyInterface以相應的屬性名稱(不同於「檢查」)提出。
顯而易見的解決方案是處理由接口IInterfaceHolder發送的每個PropertyChanged。但問題是當我編寫處理程序時:
private void GenericSelectorSelected_PropertyChanged(object sender, PropertyChangedEventArgs e) {
dynamic el = (dynamic)sender;
// here an exception is thrown, because sender (or more correctly 'el') is
// handled as IBase, and not as IInterfaceHolder
if (el.Checked) {
}
else {
}
}
如何解決此問題?如果無需爲每個IInterfaceHandler編寫分隔處理程序,就可以工作>