[英]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.