jeudi 27 octobre 2016

Iterating over all class properties

maybe quite a simple question but i have an initilised class object that is passed via parameter to another class. The class object is then read to check the values of its members and possibly alter them if incorrect.

I can access iondividual properties and change thier values but what i want to do is loop through all the integer type properties to check thier base value and alter it where neccesary.

Here is an example of the object structure:

+ Prices
++ MainPrices
+++ RelevantPrices
++++ (Int) Price

+ SubPrices
++ MainPrices
+++ RelevantPrices
++++ (Int) Price

+Rooms
++ Data
+++ (String) Name
+++ (Int) NameType
+++ (String) Location
+++ (Int) RoomNumber

What i need to do here is get Rooms.Data and loop over all its Int type parameters. I've tried using reflection but for that i require a new instance reference for the type, all i have is the initialised class object here.

Can anyone advise what might be the best way to loop over and conditionally change thier existing values please?





Aucun commentaire:

Enregistrer un commentaire