I have class MyModel and some object of MyModel.
I need for-loop or foreach properties of object without reflection. How implemented?
Class example:
public class MyModel
{
public string Level1_TypeName { get; set; }
public string Level1_AttrType { get; set; }
public string Level1_AttrValue { get; set; }
public string Level2_TypeName { get; set; }
public string Level2_AttrType { get; set; }
public string Level2_AttrValue { get; set; }
public string Level3_TypeName { get; set; }
public string Level3_AttrType { get; set; }
public string Level3_AttrValue { get; set; }
public string Level4_TypeName { get; set; }
public string Level4_AttrType { get; set; }
public string Level4_AttrValue { get; set; }
public string Level5_TypeName { get; set; }
public string Level5_AttrType { get; set; }
public string Level5_AttrValue { get; set; }
public string Level6_TypeName { get; set; }
}
I would strongly suggest that you take two actions:
TypeName
, AttrType
, AttrValue
At that point, it will be really easy to iterate over the properties without using reflection... and your code will be much clearer, too.
See more on this question at Stackoverflow