LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing a .Net IList's IEnumerable methods and properties .Net in LabVIEW 7.0

I have a .Net object that has an IList as one of its
properties. I would like to use an IEnumerator to loop
around the IList content.

Normally, I would expect to have the possibility of
invoking the GetEnumerator method from my IList, as
an IList implements IEnumerable, but I can't get the
method to be listed.

I've tried the following, to no avail:

1. Insert an Invoke Node, select the IEnumerable class,
select the GetEnumerator method, and then connect
my IList reference.

This switches the class type to IList, but leaves
the GetEnumerator method. Looks fine, but LabVIEW
then tells me that the VI is Bad, because I'm
invoking a non-existing meth
od (which isn't true,
strictly speaking :)).

2. Passing my IList reference through a To More Generic
Class node, with an IEnumerable class reference,
then invoking GetEnumerator on an IEnumerable class.

This should work, but the To More Generic Class node
refuses to receive a constant IEnumerable reference
as a target class reference.

3. Passing my IList reference through a To More Generic
Class node, with no class reference, then invoking
GetEnumerator on a Gen class.

Again, VI is bad because my To More Generic Class
node has a bad terminal (the class reference), and
the Invoke Node method is non-existing.

Any help would be greatly appreciated.

phil
0 Kudos
Message 1 of 6
(4,598 Views)
Hello

I have attached an example for populating an ArrayList ( inherits from IList and IEnumerable ),and then returning the individual elements in a similar fashion to using foreach in C#. Check it out and let me know if this is what you were trying to do.

Bilal Durrani
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(4,598 Views)
Hello,

Yes, this works, but there is one problem: I can't assume my IList is in fact an ArrayList.

In the case I'm dealing with, the developer that implemented the object I receive the IList from has told me that he was in fact using an ArrayList, so I could typecast to an ArrayList, and then use GetEnumerator from the ArrayList. But if he decides to change the implementation for whatever reason, my VI will break.

That's the whole point of using interfaces: as long as I use the interface defined by IList (which contains IEnumerable), anything could be used to implement it, and my VI would still work.
0 Kudos
Message 3 of 6
(4,598 Views)
You're right though, the methods only picks the public classes for the interface itself and not the methods it inherits. To get the enumerator though, you might want to typecast it to IEnumerable instead, using the typecast node. You should be able to get access to the GetEnumerator. I can file a corrective action request for the interface behavior.

Bilal
Bilal Durrani
NI
0 Kudos
Message 4 of 6
(4,598 Views)
Hello Bilal,

I had tried to typecast (item #2 on my original list): it doesn't work because LabVIEW seems to refuse typecasting an interface to another interface (which makes sense *if* you have access to all inherited methods of a given interface, which isn't the case...)

Filing corrective action for the interface behavior sounds like a good idea :).

Thanks,

phil
0 Kudos
Message 5 of 6
(4,598 Views)
Hello again,

Not too surprisingly, we've run into a more serious problem with this: in one case we have, the actual object implementing an interface is internal to an assembly, so we can't typecast to that class.

Has this problem been addressed by the LabVIEW development team?

Thanks,

phil
0 Kudos
Message 6 of 6
(4,598 Views)