1

我想将动态 ExpandoObjects 用于我正在处理的项目,但它没有按照我认为正确的配置进行编译。

从我所见,Mono 支持动态关键字和 ExpandoObject,所以我假设它要么是配置问题,要么在 Android 的 Mono 中是不可能的。

但是,当我尝试使用它时,我在 Visual Studio 2010 中收到以下错误消息:

错误 3 找不到编译动态表达式所需的一种或多种类型。您是否缺少对 Microsoft.CSharp.dll 和 System.Core.dll 的引用?D:\HMI\ExpandoTest\ExpandoTest\Activity1.cs 34 17 ExpandoTest

错误 1 ​​未定义或导入预定义类型“Microsoft.CSharp.RuntimeBinder.Binder” ExpandoTest

下面是简单的测试代码:

using System;
using System.Dynamic;
using System.Collections.Generic;
using System.Runtime;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace ExpandoTest
{
    [Activity (Label = "ExpandoTest", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            // Test the expando stuff
            TestExpando();
        }

        private void TestExpando()
        {
            dynamic obj = new ExpandoObject();
            int x = 10;
            obj.x = x;    // This line and the next one generate compiler errors
            obj["X"] = x;
        }
    }
}
4

1 回答 1

3

正如编译器错误消息所述,您需要添加对 Microsoft.CSharp 程序集的引用才能使用 dynamic 关键字:

添加对 Microsoft.CSharp 的引用

于 2012-06-15T02:56:24.130 回答