Is there a way to "mark" a property in a class, so that when i loop through the class' properties, i can execute a method, base on the mark or unmarked property.
I cannot do this by checking the propertyvalue.
Test Class to loop through
public class SomeClass {
public List<Object> PropertyOne { get; set; }
public List<Object> PropertyTwo { get; set; }
public SomeClass() {
PropertyOne = new List<Object>();
PropertyTwo = new List<Object>();
}
}
Reading properties:
SomeClass myObject = new SomeClass();
Type myType = myObject.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
foreach (PropertyInfo prop in props)
{
// If this prop is "marked" -> Execute code below
}
Edit: Thank you both for the great answers.