In addition to using the properties of a car, I would think about using reflection to test my models ..
Just write a generic method that gets all the properties of your class, and then use these methods:
/ get value of property: public double Number double value = (double)numberPropertyInfo.GetValue(calcInstance, null); [C#] // set value of property: public double Number numberPropertyInfo.SetValue(calcInstance, 10.0, null);
In your example:
void Main() { const int testValue=5; var test = (Test)Activator.CreateInstance(typeof(Test)); PropertyInfo valuePropertyInfo = typeof(Test).GetProperty("Value"); valuePropertyInfo.SetValue(test, testValue, null); int value = (int)valuePropertyInfo.GetValue(test, null); Console.Write(value);
the output of the above function is 0 instead of the expected 5. claiming that this could cause an error.
What do you think of this approach.
source share