锘?!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
鐜版湁涓涓檮鍔犱俊鎭璞ttachedInfo,瀹冮噷闈㈠垎鍒湁Info01銆両nfo02.....Info10涓鍏卞崄涓檮鍔犱俊鎭瓧孌碉紝鐜板湪鍙傛暟浼犺繃鏉ユ槸涓涓猻tring[]鏁扮粍錛岃鎬庝箞鎵嶈兘灝嗚繖涓暟緇勪腑鐨勫厓绱犲垎鍒搴斿埌榪欎釜瀵硅薄涓殑鍚勪釜瀛楁鍛紝閫氳繃鍙嶅皠灝卞彲浠ュ疄鐜幫紝鍗充嬌鍚庢湡AttachedInfo涓殑Info瀛楁澧炲姞錛屾垨鑰呰string[]涓殑鍏冪礌涓暟涓嶢ttachedInfo涓殑Info瀛楁涓暟涓嶄竴鑷翠篃娌″叧緋匯?/span>
AttachedInfo ai = new AttachedInfo();
//閫氳繃鍙嶅皠灝咥ttachedInfo涓殑灞炴ф槧灝勬垚涓涓睘鎬ф暟緇?/span>
Reflection.PropertyInfo[] propList = typeof(AttachedInfo).GetProperties();
//閬嶅巻璇ユ暟緇勪腑鐨勫睘鎬?/span>
propList.ToList().ForEach(p =>
{
//灝咺nfo寮澶寸殑灞炴у叏閮芥壘鍑烘潵
if (p.Name.StartsWith("Info"))
{
//鍥犱負灞炴nfo鐨勫悗涓や綅閮芥槸01銆?2鐨勬暟瀛楋紝鍥犳鍙互鍘繪帀鍓嶇紑Info,浠ユ鏉ュ搴攕tring[]鏁扮粍涓殑鍏冪礌绱㈠紩
int index = Convert.ToInt32(p.Name.TrimStart('I','n','f','o'));
//鍒ゆ柇绱㈠紩鏄惁瓚呭嚭浜唖tring[]鏁扮粍
if (index <= smr.AttachedInfos.Count())
{
//緇欐瘡涓璞′腑鐨勫瓧孌佃祴鍊?/span>
p.SetValue(ai, smr.AttachedInfos[index - 1], null);
}
else
{
p.SetValue(ai, null, null);
}
}
});