in class Person i have relation to class Position, and the class Position has a relation to class PositionTitle, and the PositionTitle has a property named Title
public class Person
{
public Position Position{get;set;}
}
public class Position
{
public PositionTitle PositionTitle{get;set;}
}
public class PositionTitle
{
public string Title{get;set;}
}
i have a string “Person.Position.PositionTitle.Title”, how can i get this property of person with this string??
You’ll need to split the string by dots, and then use reflection to get each property by name. You can get the type of the property using
PropertyInfo.PropertyType– then use that to fetch the next property in the chain. Something like this:You may well want to tweak this for binding flags etc, but it’s the right basic idea.