Basically, what I want to do is loop over the list of properties on a class, and where they are a particular type I will check a property of that owned property, then set another property to true.
I wrote the code below to illustrate what I want to do, however it will not compile because it says cannot convert type System.Reflection.PropertyInfo to type ThermodynamicState. In addition it gives the warning that the given expression is never of ThermodynamicState type.
How do I convert each property in the list of properties reflection gives into an object of that type?
public void BasisChanged()
{
foreach (ThermodynamicState state in this.GetType().GetProperties().Where(p => p is ThermodynamicProperty && !((ThermodynamicProperty)p).IsBasis))
{
state.BasisChanged = true;
}
}
Aucun commentaire:
Enregistrer un commentaire