Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through class properties dynamically 1

Status
Not open for further replies.

sensoukami

Technical User
Feb 25, 2003
19
0
0
CA
Hello!

I apologize if this is the wrong place in the forum. I
wasnt sure where else to go, and I am in a screaming rush
(work pressure).

------------------------

I need to loop through the properties of a class, look at
those properties, and then "do stuff" depending on whether
or not the property is of type string.

Problem1:

I dont know how to loop through a class's properties. I
have done some digging, and "reflection"
and "PropertyInfo" seem to have what I need, and I have
been playing around, but I am kind of lost.

Problem2:

Once I can do that, how can I dynamically alter those
properties without just using the properties name?

Any general advice or tips would be huge.

Thanks,
 
Public Sub GetPropertiesDataType()

Dim prop As System.Reflection.PropertyInfo

For Each prop In Me.GetType.GetProperties()

If TypeOf prop= System.String Then
msgbox("This is a String!")

Next prop

End Sub

something of the sort will work,just play around a bit with the code
 
Ok, that basically works (except I had to do prop.PropertyType.FullName = "System.String")

Problem:

How can I now change the property values of the underlying object. I have tried a million and one things, but cant seem to do it.
 
This is only after a minute or so looking at this so if I'm way off the mark apologies but try what chmohan suggested and then to change the value use:
Code:
prop.SetValue =
Value
Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top