我正在嘗試使用ImpromptuInterface
來解決我在這裏遇到的問題。 Adding Interface Implementation to ExpandoObject。'ExpandoObject'不包含'PropertyChanged'的定義
我現在能夠訪問我的基類中的接口的各種屬性,但我不能再訂閱ExpandoObject的PropertyChanged事件。
在排除故障時,我能夠簡化問題,如圖所示。
Service.cs
using ImpromptuInterface;
public Service()
{
InitializeComponent();
dynamic expando = new ExpandoObject();
try
{
INotifyPropertyChanged obj = Impromptu.ActLike(expando);
obj.PropertyChanged += obj_PropertyChanged;
}
catch (Exception ex)
{
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
try
{
INotifyPropertyChanged obj = Impromptu.ActLike<INotifyPropertyChanged>(expando);
obj.PropertyChanged += obj_PropertyChanged;
}
catch (Exception ex)
{
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
}
private void obj_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
throw new NotImplementedException();
}
我收到一個錯誤,指出
'System.Dynamic.ExpandoObject' 不包含一個定義 '的PropertyChanged'
每次嘗試在構造函數中掛接事件處理函數時都會發生。
事件日誌1
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Dynamic.ExpandoObject' does not contain a definition for 'PropertyChanged'
at CallSite.Target(Closure , CallSite , Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ActLike_INotifyPropertyChanged_dc51b6c65bf147d0b5f35218102e3c11.add_PropertyChanged(PropertyChangedEventHandler value)
at Service..ctor()
事件日誌2
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Dynamic.ExpandoObject' does not contain a definition for 'PropertyChanged'
at CallSite.Target(Closure , CallSite , Object)
at ActLike_INotifyPropertyChanged_dc51b6c65bf147d0b5f35218102e3c11.add_PropertyChanged(PropertyChangedEventHandler value)
at Service..ctor()
不允許我使用ImpromptuInterface
這種方式?
從我玩過的幾分鐘內,它看起來像一個'ImpromptuInterface'的bug。我會[報告錯誤](https://github.com/ekonbenefits/impromptu-interface/issues) –