【发布时间】:2012-06-15 01:31:49
【问题描述】:
我想在我正在处理的项目中使用动态 ExpandoObjects,但它没有按照我认为正确的配置进行编译。
据我所见,Mono 支持 dynamic 关键字和 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;
}
}
}
【问题讨论】:
-
注意:我尝试在 MonoDevelop 3.0 下编译并得到相同的错误。不确定它是否相关,但我也安装了 Unity,它安装了另一个版本的 MonoDevelop。不过,这两者似乎并没有以任何其他方式相互干扰。
标签: c# dynamic xamarin.android expandoobject