08-10-2020 07:04 PM
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.
Solved! Go to Solution.
08-11-2020 02:34 AM - edited 08-11-2020 02:34 AM
Hi testergi, Are you able to provide a TestStand specific example of the sort of thing you would like to do?
08-11-2020 06:00 AM
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.
08-11-2020 09:15 AM - edited 08-11-2020 09:17 AM
Two choices:
1) You really want to keep it as a .NET Class instance to be passed into other .NET methods.
2) The object is just raw data and you just want to make a copy of that data in TestStand
Hope this helps,
-Doug
08-11-2020 07:48 PM - edited 08-11-2020 08:14 PM
Hi @dug9000 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.