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?)

这是 VS Express (2012) 的限制,还是我做错了什么?

4

1 回答 1

1

确保包含以下命名空间和程序集引用:

命名空间:Microsoft.CSharp.RuntimeBinder

“使用 Microsoft.CSharp.RuntimeBinder”语句应该可以解决这个问题。

程序集:Microsoft.CSharp(在 Microsoft.CSharp.dll 中)

  1. 右键单击项目中的 References 文件夹。
  2. 选择添加参考。
  3. 选择 .NET 选项卡(如果不是 .NET Framework 程序集,则选择“浏览”按钮)。
  4. 双击错误消息中包含命名空间的程序集。
  5. 按确定按钮。
于 2013-03-28T06:55:08.797 回答