convert string to property when the name in the same

  • Thread starter Thread starter tony
  • Start date Start date
T

tony

Hello!

In the code below there is two different switches.
It's the second switch that is interesting for me.
Here I have three different case called case "MStl" :, case "MSlg" : and
case "Temp" :
In the code belonging to case "MStl" :, case "MSlg" : and case "Temp" there
is some if clauses.
The literal "C_min" , "C_aim" and "C_max" in this if clauses has the same
name as the property
C_min, C_aim and C_max in the comp instance.
When I come to the code belonging to case "MStl" :, case "MSlg" : and case
"Temp" I know
that colName is either "C_min" or "C_aim" or "C_max".

I wonder if it's possible to convert this colName so I could use
the right property directly which is either comp.C_min or comp.C_aim or
comp.C_max
I know that I can't write in this way val = comp.colName; but perhaps
something
similar using the right property without using if clause.

//Tony


switch(..)
{
....
break;
case "C_max" :
case "C_aim" :
case "C_max" :
switch(comp.Element)
{
case "MStl" :
case "MSlg" :
case "Temp" :
if (colName == "C_min")
val = comp.C_min;
else if ( colName == "C_aim")
val = comp.C_aim;
else
val = comp.C_max;

rowList.Add( getGridValueObj( val, comp.Element ));
break;
....

//Tony
 
Back
Top