Monday, March 26, 2012

Loop through class using reflection - code posted - how do i loop through array?

Code is posted below - i can loop through a class and get the properties and values, but when one of the properties is a arraycollection - and it's value is getinfo[0] getinfo[1]. How do i loop through the getinfo collection automatically. So if it's a array - loop through each array item and get all the properties in that array.

Dim

clszcpAs Type = test.GetType()Dim properties()As PropertyInfo = clszcp.GetProperties()ForEach pAs PropertyInfoIn propertiesIf p.PropertyType.IsArrayThen

'WHAT CODE DO I PUT HERE? (i want to loop through the array)

if p.propertytype.IsArray.name = getinfo[] then

i want to loop through getinfo[] and get all the properties of getinfo -

getinfo[0]

Else

Console.WriteLine(p.Name)

Console.WriteLine(p.GetValue(test,

Nothing))EndIfNext

if it is an array use the LBound & UBound properties to loop through the array

ex:

dim ictr as integer

for ictr = LBOUND(myarray) to UBOUND(myarray)

msgbox myarray(ictr)

next

hope this helps:

Lex

0 comments:

Post a Comment