'ExpandoObject' 不包含 'PropertyChanged' 的定义
'ExpandoObject' does not contain a definition for 'PropertyChanged'
我正在尝试使用 ImpromptuInterface
来解决我在这里遇到的问题。 .
我现在可以在我的基础中访问我的接口的各种属性 class 但我不能再订阅 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' does not contain a definition for
'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
使用 DLR,而 DLR 无法使用显式接口调用,而这正是它在 Expando 上的实现方式。通过让代理检查它的目标是否实现即兴包装的确切接口,可能可以进行一般性修复。我得再考虑一下。使用此 issue.
进行跟踪
作为针对此特定问题的变通方法,Dynamitey.Dynamic.Dictionary:BaseDictionary 的工作方式与 expando 类似,并且将 PropertyChanged 作为正常事件 属性。
我正在尝试使用 ImpromptuInterface
来解决我在这里遇到的问题。
我现在可以在我的基础中访问我的接口的各种属性 class 但我不能再订阅 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' does not contain a definition for '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
使用 DLR,而 DLR 无法使用显式接口调用,而这正是它在 Expando 上的实现方式。通过让代理检查它的目标是否实现即兴包装的确切接口,可能可以进行一般性修复。我得再考虑一下。使用此 issue.
作为针对此特定问题的变通方法,Dynamitey.Dynamic.Dictionary:BaseDictionary 的工作方式与 expando 类似,并且将 PropertyChanged 作为正常事件 属性。