[英]dynamic keyword with ExpandoObject to attach and remove properties
[英]Does Mono for Android Support “dynamic” Keyword & ExpandoObject?
我想为我正在使用的项目使用动态ExpandoObjects,但它不能用我认为正确的配置进行编译。
从我所看到的Mono支持动态关键字和ExpandoObject,所以我假设它是一个配置问题或者在Mono for Android中不可能。
当我尝试使用它时,我在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;
}
}
}
正如编译器错误消息所述,您需要添加对Microsoft.CSharp程序集的引用才能使用dynamic关键字:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.