ExpandoObject中的List

Dav*_*eer 5 c# expandoobject

dynamic model = new ExpandoObject();
model.Data = "asdf";

List<dynamic> listOfx = new List<dynamic>();
for (int i = 0; i < 3; i++) {
    dynamic x = new ExpandoObject();
    x.ID = i;
    x.Name = "test" + i.ToString();
    listOfx.Add(x);
}
model.listOfx = listOfx;
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我可以在模型内部看到数据,但不能看到listOfx.

问题:如何在ExpandoObject中获取列表(或IEnumerable)

更新解决方案: 在此输入图像描述

因为我无法在本地窗口看到lifOfx,所以我觉得它不起作用.在这里(通过y)你可以看到它.:-)

seh*_*ehe 4

我无法在 Mono 2.10 上重现类似问题:

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

using System;

public class Program
{
    public static void Main(string[] args)
    {
        dynamic x = new ExpandoObject();
        x.Data ="test";
        x.Arr = new [] { "test1","test2"};
        x.Lst = new List<string> { "aap", "noot", "mies" };

        Console.WriteLine(string.Join(", ", x.Arr));
        Console.WriteLine(string.Join(", ", x.Lst));
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

/tmp @ dmcs test.cs && mono test.exe
test1, test2
aap, noot, mies
Run Code Online (Sandbox Code Playgroud)

我很快就会在 Windows 上重新测试。

更新已测试以下内容:

  • linux 编译的 (dmcs) 二进制文件在 Windows 上运行 Mono 2.10:OK
  • linux 编译的 (dmcs) 二进制文件在带有 MS.NET 4.0 的 Windows 上运行:好的
  • Windows 编译的 (dmcs) 二进制文件在 Windows 上运行 Mono 2.10:OK
  • Windows 编译的 (dmcs) 二进制文件在使用 MS.NET 4.0 的 Windows 上运行:好的
  • Windows 编译的 (csc.exe) 二进制文件在使用 Mono 2.10 的 Windows 上运行:OK
  • Windows 编译的 (csc.exe) 二进制文件在使用 MS.NET 4.0 的 Windows 上运行:好的

在linux上我只测试了mono本身编译的二进制文件,但我预计不会出现任何问题。也许在 List<> 中存储动态有一些微妙的不同,我现在将测试这一点