NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Return complex .NET objects in step

Solved!
Go to solution

Anyone have examples on returning complex .NET objects in a step?  For example, I have the following class and want to return and use in expressions.  How can I get access to the public properties?

 

public class Person

{

    public string FirstName { get; set; }

    public string LastName { get; set; }

}

 

Any help is appreciated.

0 Kudos
Message 1 of 5
(2,056 Views)

Hi testergi, Are you able to provide a TestStand specific example of the sort of thing you would like to do?

0 Kudos
Message 2 of 5
(2,013 Views)

Hi @SercoSteveB, thanks for reaching out.

 

I'm trying to understand how to pass and return complex .NET objects in TestStand steps.

 

For example and using the Person object above, let's say I have a static method in the Class like below.  NOTE: This uses a very basic Class and nothing to with TestStand users.

 

public static bool GetPerson(int id, out Person person, out bool errorOccurred, out int errorCode, out string errorMsg)

{

    // logic to get and return person.

}

 

I need to understand how to setup the parameters in the Step Settings pane to return the Person object.  I understand I could simplify and break out the parameters to return FirstName and LastName properties, but seems like there should be a way to return/use the entire object.  I assume you need to setup the Person object to be stored in a Local/File/Station variable, but also not sure how to setup.

 

Once I get the Person object, I need to understand how to setup the parameters in the Step Settings pane to pass the Person object to other steps.  For example:

 

public static bool ProcessPersonData(int id, Person person, out bool errorOccurred, out int errorCode, out string errorMsg)

{

    // logic to process something based on Person object.

}

 

Thanks again.

 

0 Kudos
Message 3 of 5
(2,001 Views)
Solution
Accepted by topic author testergi

Two choices:

 

1) You really want to keep it as a .NET Class instance to be passed into other .NET methods.

  • Store the class object in an object reference variable (a Local variable most likely)
  • Pass in that object references variable to subsequent calls that take that class type.
  • If you want property values from the class instance, use a .NET step and select the corresponding class and use the object reference variable as the class instance. Select the property you want to get the value of in the .NET step and store the value in a variable of the appropriate type (likely a Local variable)

2) The object is just raw data and you just want to make a copy of that data in TestStand

  • Make the class a struct (i.e. value type) instead of a class (i.e. reference type)
  • For structs you can define an equivalent TestStand type then you can use instances of that teststand type as the struct when calling .NET methods.
  • If you really want a reference type and want to hold onto that specific instance rather than make a copy, you should go with option 1) above instead.

 

Hope this helps,

-Doug

Message 4 of 5
(1,993 Views)

Hi @ and thank you for also helping out.

 

I believe my steps to retrieve and pass an object (Person in this example) between steps is now working.  I'm still scratching my head on how to actually see the properties data.  I'm storing the object in a locals, called Locals.ThePerson, but I'm not able to view the FirstName and LastName properties while stepping through the sequence.

 

All that is shown in the Variables Value column is .NET Type: MyAssembly.Person.

 

In addition, I thought I would have code completion on the properties in the steps expressions.  For example, in the Post-Expression, I tried Locals.ThePerson.   thinking I would see FirstName and LastName show up, but only shows "Show TestStand API".

 

Thanks again.

0 Kudos
Message 5 of 5
(1,969 Views)