2013-03-28 91 views
1
using System.Dynamic; 

... 

public partial class Form1 : Form 
    { 
     ... 
     private void button1_Click(object sender, EventArgs e) 
     { 
      dynamic CBT = new CustomBindingTest(); 
      CBT.DynamicMethodExample(); 
     } 
    } 

    public class CustomBindingTest : DynamicObject 
    { 
     public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) 
     { 
      MessageBox.Show(binder.Name); 
      try { return base.TryInvokeMember(binder, args, out result); } 
      catch (RuntimeBinderException e) { result = null; return false; } 
     } 
    } 

我得到以下錯誤:The type or namespace name 'RuntimeBinderException' could not be found (are you missing a using directive or an assembly reference?)Visual Studio如何識別RuntimeBinderException?

這是VS快遞(2012年)的限制,還是我做錯了什麼?

+1

'使用Microsoft.CSharp.RuntimeBinder;'? – 2013-03-28 06:53:00

回答

1

確保您已包括以下命名空間和裝配參考:

命名空間:Microsoft.CSharp.RuntimeBinder

A 「使用Microsoft.CSharp.RuntimeBinder」 語句應該解決這個問題。

大會:Microsoft.CSharp(在Microsoft.CSharp.dll)

  1. 右鍵點擊引用您的項目文件夾中。
  2. 選擇添加引用。
  3. 選擇「.NET」選項卡(或者如果它不是.NET Framework程序集,請選擇「瀏覽」按鈕)。
  4. 雙擊錯誤消息中包含名稱空間的程序集。
  5. 按下OK按鈕。
+0

Doh。看了很多地方,從未見過任何提及'Microsoft.CSharp.RuntimeBinder'。本來想到這將在'System.Dynamic'中。奇怪。謝啦! – TimFoolery 2013-03-28 07:02:09