2016-12-28 11 views
3

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この方法を使用することはできないだろうか?

+0

私は数分間、「ImpromptuInterface」のバグのように見えました。私は[バグを報告する](https://github.com/ekonbenefits/impromptu-interface/issues) –

答えて

0

ImpromptuInterfaceはDLRを使用しているため、DLRは明示的なインターフェイスコールでは機能しません。これはExpandoでの実装方法です。プロンプトにターゲットが正確なインタフェースを実装しているかどうかをチェックすることで、一般的に固定される可能性があります。私はそれについてもっと考えなければならないだろう。このissueのトラッキング

Dynamitey.Dynamic.DictionaryBaseDictionaryはexpandoと同じように動作し、通常のイベントプロパティとしてPropertyChangedを持っています。

関連する問題