简体   繁体   English

Mono for Android是否支持“动态”关键字和ExpandoObject?

[英]Does Mono for Android Support “dynamic” Keyword & ExpandoObject?

I want to use dynamic ExpandoObjects for a project I'm working on, but it doesn't compile with what I think is the correct configuration. 我想为我正在使用的项目使用动态ExpandoObjects,但它不能用我认为正确的配置进行编译。

From what I can see Mono supports the dynamic keyword and ExpandoObject, so I am assuming it is either a configuration issue or somehow it's not possible in Mono for Android. 从我所看到的Mono支持动态关键字和ExpandoObject,所以我假设它是一个配置问题或者在Mono for Android中不可能。

When I try to use it though, I get the following error messages in Visual Studio 2010: 当我尝试使用它时,我在Visual Studio 2010中收到以下错误消息:

Error 3 One or more types required to compile a dynamic expression cannot be found. 错误3无法找到编译动态表达式所需的一种或多种类型。 Are you missing references to Microsoft.CSharp.dll and System.Core.dll? 您是否缺少对Microsoft.CSharp.dll和System.Core.dll的引用? D:\\HMI\\ExpandoTest\\ExpandoTest\\Activity1.cs 34 17 ExpandoTest D:\\ HMI \\ ExpandoTest \\ ExpandoTest \\ Activity1.cs 34 17 ExpandoTest

Error 1 Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported ExpandoTest 错误1未定义或导入预定义类型“Microsoft.CSharp.RuntimeBinder.Binder”ExpandoTest

Here is the simple test code: 这是简单的测试代码:

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;
        }
    }
}

As the compiler error message states, you need to add a reference to the Microsoft.CSharp assembly in order to use the dynamic keyword: 正如编译器错误消息所述,您需要添加对Microsoft.CSharp程序集的引用才能使用dynamic关键字:

添加对Microsoft.CSharp的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM