var settings = new SettingsClass();
settings.SpecificValue = new List<SpecificValueClass>();
Run Code Online (Sandbox Code Playgroud)
这是我的C#项目中的代码示例。
我有一个使用此代码示例导入.dll的python脚本,我想在python脚本中创建此settings.SpecificValue变量。
没有在C#中创建可以在python代码中调用的函数的方式,是否可以实现?
public class SettingsClass
{
public bool Timesync { get; set; }
public string SystemName { get; set; }
public string Timezone { get; set; }
public List<SpecificValueClass> SpecificValue{ get; set; }
}
public class SpecificValueClass
{
public string ID { get; set; }
public int value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在python中,我想这样称呼它:
settings = SettingsClass() <-- this call is no problem and I can do it with a dotNet library in python
settings.SystemName = systemname
settings.Timesync = timesync
settings.Timezone = "%s//%s" % (timezone1,timezone2)
settings.SpecificValue = ... <-- not sure how to make this to create a empty List / empty whatever so I can add 2 objects of the type SpecificValueClass
Run Code Online (Sandbox Code Playgroud)
(也可以创建创建两个对象的obSpecificValueClass对象)所以我唯一无法使用的部分是设置的初始化.SpecificValue是通用列表...
任何帮助,将不胜感激
最终使用TestComplete的dotNet库使它工作,但我想它与python的clr包相同。只需自己编写泛型部分即可,通常C#会使用这些标记:
typeListOf = dotNET.System.Type.GetType("System.Collections.Generic.List`1")
objType = dotNET.namespace.SpecificValueClass.zctor().GetType()
paramTypes = dotNET.System.Array.CreateInstance(dotNET.System.Type.GetType("System.Type"), 1)
paramTypes.SetValue(objType, 0)
typeListOfString = typeListOf.MakeGenericType(paramTypes)
newValue = dotNET.namespace.WattPeakValues.zctor()
newValue.ID = 1
settings.SpecificValue.Add(newValue)
Run Code Online (Sandbox Code Playgroud)