之后,我必须通过字符串(通过featuresHome
完成)在var property = typeof (featuresHome) .GetProperty ("homePosition");
类中找到一个属性,然后我必须设置positionLake
的{{1}}属性。
代码:
homePosition
目标是通过字符串找到“ featuresHome”类的属性,然后设置属性的值(“ PositionLake”)
谢谢!
答案 0 :(得分:0)
featuresHome FeaturesHome = HomeList.Last().FeaturesHome;
var property = typeof(featuresHome).GetProperty("homePosition");
只需获取其HomePosition
属性:
property.SetValue(FeaturesHome.HomePosition.PositionLake, "Mono Lake", null);
HomePosition hp = new HomePosition {PositionLake = "Mono Lake"}
然后设置FeatureHome的HomePosition
属性:
property.SetValue(FeaturesHome, hp, null);