10-22-2009 07:52 AM
Hello,
I'm using the System.Collections.Generic.List<T> class, to store some stuff :).
Now when I used the .NET adapter, went to mscorlib.dll (2.0.0.0) I can't see any of the generic classes.
The only availible item is System.Collections.Generic.KeyNotFoundException.
Why is that so?
Can't I call methods and properties on the Generics, to work directly on them?
Now I know I can cast the List<T> on the System.Collections.ICollection or the System.Collections.IList for example, to access some methods and properties, but why coulnd't I just use the List<T> class directly?
Thanks,
Maciej
Solved! Go to Solution.
10-23-2009 09:37 AM
The .NET adapter does not currently support generics. You can interact with these objects using any non-generic interfaces or non-generic base classes or derived classes as you mentioned, or by writing a higher-level wrapper API around the operations that are important to you.
Adding support for generics is not as simple as just allowing the selection of the List<T> class. List<T> by itself is not a fully specified type. It would also require a way of specifying what the generic parameters (i.e. T in this case) are too. It is something that might be considered for a future version of TestStand.
Hope this helps explain things,
-Doug
10-23-2009 10:02 AM - edited 10-23-2009 10:03 AM
As dug9000 mentioned, this is a limitation in TestStand's .NET support that we plan to address in a future version of TestStand.
The workaround you suggest is viable, but you lose the type safety of the collection. If you want to retain the type safety of the Generic collection, you can create a concrete collection class that derives from System.Collections.Generic.IList<T>and use an internal concrete instance of List<T> to implement the interface. The C# editor can help with a lot of the boilerplate typing and if you need to do this for a lot of classes; you could create a Visual Studio code snippet to make it really fast to implement.
Basically, you can use the following steps:
I have attached an example that shows this. It uses VS2008 and TestStand 4.2. Creating the concrete collection class took only about 5 minutes, so while this is far from ideal, it isn't terribly painful either.
David Rohacek
National Instruments
10-26-2009 10:10 AM
Doug, David,
Thank you both for your feedback.
David thanks for the tip with the concrete interface implementation idea.
I did not know that function in Visual Studio, this will get me up to speed.
Thank you both,
Maciej
02-13-2021 09:13 AM
@dug9000
Had the following recent thread that you might be able to answer. Re: Using IEnumerable<string> Variables - NI Community
I reviewed your attached example. My question is... how can you setup a variable (local, file, station) for generic (List<string>, IEnumerable<string>) to be passed into a .NET module? Seems like you should be able to set like an Array of Strings instead of having to call another method to return the object and store in variable. Also, is there a way to use describe in expression values? Something like arrays ( {"one", "two" } )?
Any help is appreciated.
02-15-2021 10:07 AM
Answered in other thread. See other thread for details.