I'm trying to find the best way to tag properties of an object as required/optional/ignored.
public enum classtype
{
A,
B,
C,
D
}
class example
{
public classtype type { get; set; }
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
public int d { get; set; }
}
What im doing so far:
public static void DoSomething(List<example> examples)
What i want is something like this:
public static void DoSomething(List<example> examples)
{
foreach (example ex in examples)
{
foreach (PropertyInfo prop in ex.GetType().GetProperties())
{
if (prop.isRequired)
{
DoSomethingElse(prop);
}
else if (prop.isOptional)
{
DoThis(prop);
}
...
}
}
}
i.e.
- -type.A: a.req, b.opt, c.req, d.ign
-type.B: a.ign, b.req, c.opt, d.req
-...
The goal is to have a way to iterate over the objects and their properties.
I'm thinking to use a dictionary to define types, but that doesn't strike me as the most efficient way to implement this.