How can I traverse a list of properties of a class ?

  • Thread starter Thread starter Tim Conner
  • Start date Start date
T

Tim Conner

Hi,

I have a class that has defined like 30 string constants.
I need to test a string against each one of this contants
to see if it matches any of them.
I was thiking to have this constants in a
StringCollection, or String[], but I really don't want to
duplicate code, since this list can vary.

So, is there any approach to this programmatically ? I
mean, without having to write a very big "if...else
if..elseif ..." statement ?
 
Tim Conner said:
I have a class that has defined like 30 string constants.
I need to test a string against each one of this contants
to see if it matches any of them.
I was thiking to have this constants in a
StringCollection, or String[], but I really don't want to
duplicate code, since this list can vary.

So, is there any approach to this programmatically ? I
mean, without having to write a very big "if...else
if..elseif ..." statement ?

It sounds like you might want to use reflection - get the appropriate
type (eg using typeof(...)) and then call GetFields or GetProperties on
it.
 
Back
Top