Forum Discussion

fayrehouse's avatar
fayrehouse
Frequent Contributor
12 years ago
Solved

System.Collections.Specialized.StringCollection ??

Hi All,



I have an object in our AUT that has a method that takes an object of the above type as a parameter.... And I'm having trouble defining an object of that type.



Can anyone correct me below?




  var myAssessments;


  myAssessments = dotNET.System.Type.GetType("System.Collections.Specialized.StringCollection");


  myAssessments.add("AA000191");



FWIW, I have System.Collections (from the GAC) listed in the CLR Bridge page of the project properties.... Don't think that's made any difference though!



What do I need to change to have an object of type "Specialized.StringCollection" - and how to add strings to it?



Thanks



Steve

 

  • Hi Steve,



    With TC 9.20 after adding "System, version=4.0.0.0, ..." to the CLR bridge, the following works:




    function testTypeCollectionFromDotNet()

    {

     
    var myAssessments = dotNET.System_Collections_Specialized.StringCollection.zctor();



      myAssessments.add("AA000191");



      Log.Message(myAssessments.Item(0));

    }



    For more info,this will help.



    Sincerely


  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Steve,



    With TC 9.20 after adding "System, version=4.0.0.0, ..." to the CLR bridge, the following works:




    function testTypeCollectionFromDotNet()

    {

     
    var myAssessments = dotNET.System_Collections_Specialized.StringCollection.zctor();



      myAssessments.add("AA000191");



      Log.Message(myAssessments.Item(0));

    }



    For more info,this will help.



    Sincerely


  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Steve,



    To quote the documentation:









    Note:

    Normally, the class constructor name is _ctor(). A class can have several constructors ( _ctor(), _ctor2(), _ctor3(), etc). However, in VBScript an identifier cannot begin with an underscore ( _ ). So, in order for _ctor methods to be compatible with VBScript, TestComplete modifies the names of these methods, namely, it replaces the leading underscore with the letter z. For example, to call the _ctor3 method in your script, you should use zctor_3.



    Sincerely
  • fayrehouse's avatar
    fayrehouse
    Frequent Contributor
    Thanks Simon,



    That appears to be exactly what I was missing!



    Out of interest.... zctor??? What the ?!?!? is that?! :)



    Cheers



    Steve