初始化C#List< T>从IronPython? [英] Initialize C# List<T> from IronPython?

查看:53
本文介绍了初始化C#List< T>从IronPython?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个相对较深的对象树,需要从IronPython进行初始化.

I have a relatively deep object tree in C# that needs to be initialized from IronPython.

我是python的新手,我在数组的初始化中苦苦挣扎.

I'm new to python and I'm struggling with the initialization of arrays.

例如,假设我在C#中有这些类

So as an example - say I have these classes in C#

public class Class1
{
    public string Foo {get;set;}
}

public class Class2
{
    List<Class1> ClassOnes {get;set;}
}

我可以像这样在Class2中初始化数组:

I can initialize the array in Class2 like so:

var class2 = new Class2(
    ClassOnes = new List<Class1>()
    {
        new Class1(Foo="bar")
    });

在IronPython中-我正在尝试这样做:

In IronPython - I was trying this:

bar = Class2
bar.ClassOnes = Class1[Class1(Foo="bar")]

但我总是收到此消息:

预期的Array [Type],获得Class1

expected Array[Type], got Class1

有什么想法吗?

推荐答案

在Class2()上犯了一个错误-这就是我举一个例子而不是发布真实代码的结果!

Made a mistake on the Class2() -- that's what I get for making an example instead of posting real code!!!

对于它的价值-我能够使用像这样的实际实例来初始化列表:

For what it's worth - I was able to initialize the List with actual instances like this:

from System.Collections.Generic import List

bar.ClassOnes = List[Class1]([Class1(Foo="bar")])

非常感谢卡梅隆!

这篇关于初始化C#List&lt; T&gt;从IronPython?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆