cancel
Showing results for 
Search instead for 
Did you mean: 

Create a generic List from C# dll in python script

SOLVED
Highlighted
Frequent Contributor

Create a generic List from C# dll in python script

Using my C# dll in TestComplete as CLR Bridge and want to create a python script routine where I initialize the settings.SpecificValue with a List of SpecificValueClass Objects. Does someone know how to do this?
Here more details about my code:

 

var settings = new SettingsClass();
settings.SpecificValue = new List<SpecificValueClass>();

This is the code example in my C# project.

I have a python script which imports the .dll with this code example and I want to create this settings.SpecificValue variable within the python script.

Is it somehow possible without making a function in C# which I can call within python code.

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

In python I want to call it like this:

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 

(creating the 2 objects ob SpecificValueClass is also possible) So the only part that I can not get to work is the initialization of the settings.SpecificValue as it is a generic List ...

Any help would be appreciated

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Contributor

Re: Create a generic List from C# dll in python script

 

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)

 

 

Got it to work! You have to programm the part that usually C# makes for you with the <T> ... little confusing but it works now

5 REPLIES 5
Community Manager

Re: Create a generic List from C# dll in python script

Hi @Lagencie,

 

Let's ask our coding guru. @AlexKaras@tristaanogre@Vallalarasu_P, can you suggest here?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Frequent Contributor

Re: Create a generic List from C# dll in python script

Another question, would it be possible / good to use TestLeft in this case so I can integrate the code? We never used TestLeft before but from what I have looked over, it might help in this case

Community Hero

Re: Create a generic List from C# dll in python script

Hi,

 

> would it be possible / good to use TestLeft in this case

With TestLeft you have all your test code written in .Net (or Java), so you have direct access to all .Net infrastructure and functionality.

Note however, that TestLeft supports Desktop and Web only and not all technoligies supported by TestComplete. So you should check if TestLeft supports development environment/technologies required for your tested application.

 

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Frequent Contributor

Re: Create a generic List from C# dll in python script

 

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)

 

 

Got it to work! You have to programm the part that usually C# makes for you with the <T> ... little confusing but it works now

Community Manager

Re: Create a generic List from C# dll in python script

Congratulations!

We need a new badge for you - Scripting Guru Smiley Wink

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors