Copying a Collection to an Array

Posts   
 
    
Posts: 5
Joined: 12-Jun-2005
# Posted on: 12-Sep-2005 06:26:48   

Hi - just wondering if anyone can tell me a quick and easy way to copy a collection to an array.

I have read that the standard ICollection interface provides a "CopyTo" method that copies the collection data into an array.

Is ICollection the basis of the LLBLGEN collection classes? If yes - can I add a new simple custom routine to get at the CopyTo method in my Collection classes?

If no - is there an easy way to iterate through all the field properties of the collection, so I can write a generic routine to convert a collection to an array?

I am actually wanting to copy collections to an Excel Worksheet, and so would like a generic way to convert any collection to an array and then use the array to copy the data in to Excel.

Any help or ideas would be useful.

Cheers

Paul Smith

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Sep-2005 09:54:29   

EntityCollection classes already have a CopyTo method which copies the contents to an IEntity or IEntity2 array. Are these not working for you?

Please consult the reference manual in the llblgen pro folder for details on these methods.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 5
Joined: 12-Jun-2005
# Posted on: 12-Sep-2005 11:41:58   

Thanks for the reply I have tried the CopyTo but it is not what I need. It gives me an array of the entities, I need a multi-dimension array with all the values in it. E.g. A row for every entity, a column for every field in the entity.

I got my original msg wrong - what I meant to say was:

I have read that the standard ICollection interface provides a "ToArray" method that copies the collection data into an array.

I think the ToArray would do what I need it to for a standard collection, but it doesn't seem to be there or is not exposed in LLBLGEN collections.

If this is not available, could you then tell me if it is possible to iterate through the fields in a collection, so that I could do something like the below to fill in an array with all the data in a collection. I could then write a generic function to do it for any collection.

redim MyArray(MyCollection.count, MyCollection.FieldCount) For each MyEntity in MyCollection iii = iii +1 For each EntityField in MyEntity jjj = jjj+ 1 MyArray(iii,jjj) = EntityField.Value Next Next

Cheers

Paul

Posts: 5
Joined: 12-Jun-2005
# Posted on: 12-Sep-2005 11:47:12   

Ahhh - I think I have found thew fields property and am happy!

Thanks for your time.