How can I get the property value type of each property in a class?
this.GetType().GetProperties().ToList().ForEach(p => {
switch(typeof(p.GetValue(this, null))) {
case float:
...
break;
case string:
...
break;
}
});
This produces the error Cannot resolve symbol p
SOLUTION: I ended up going with LINQ to SQL. Just cleaner and easier to deal :). Thanks Jon
I don’t get that as a problem – I get:
You can’t switch on types. Using
ForEachlike that in general is fine though.Sample code:
Now admittedly I generally wouldn’t use
ForEachhere – I’d just use aforeachloop:Personally I think that’s cleaner, simpler to read, and easier to debug.