Forum Discussion

socc3rpr0's avatar
socc3rpr0
Occasional Contributor
9 years ago

Creating C# List Using dotNET

Hello, 

 

I want to create a script using TestComplete to test a C# API one of my colleagues wrote. How would I go about creating a C# list with TestComplete since it requires all arguments to be passed to a C# function, even though all arguments have a default value. I am using the CLR Bridge to load the DLL for the API. I  want to use dotNET in order to call these functions. 

 

// Here are two C# functions I want to call:

 

1) public short SendRequest(List<IP> ipList, double timeout = 2.0)

 

2) public void RefreshWindow(List<Devices> deviceList = null, int maxAttempts = 3, double timeout=2.0) 

 

 

// So Far all I got to work is this but that just creates a list of 'Sytem.Object' not a list of the class I want. 

// I found this example here

 

var typeListOf = dotNET.System.Type.GetType("System.Collections.Generic.List`1");
var paramTypes = dotNET.System.Array.CreateInstance(dotNET.System.Type.GetType("System.Type"), 1);
var objType = dotNET.System.Type.GetType("System.Object");
paramTypes.SetValue(objType, 0);
var typeListOfString = typeListOf.MakeGenericType(paramTypes);
var list = dotNET.System.Activator.CreateInstance_3(typeListOfString);

Any help would be greatly appreciated.