這是常規操作,以前也沒碰到類似問題 。
Type type=typeof(JiChuKu);
var Properties=type.GetProperties();
var des=type.GetProperty("屬性名");
des.SetValue(jckCurrentKong,屬性值,null);
今天碰到了,
如果 屬性值 是string,值時,上述代碼沒問題;
但如果 屬性值是 bool型別時,怎么也通不過了呀。
試過下列方法都不行
des.SetValue(jckCurrentKong, false.ToString(), null);
des.SetValue(jckCurrentKong, "false", null);
des.SetValue(jckCurrentKong, 0, null);
請高手解決下
另有一個問題很困惑,這么簡單的一個問題,百度上搜了近兩個小時,就沒找到類似的提問...
uj5u.com熱心網友回復:
值直接用false/trueuj5u.com熱心網友回復:
des.SetValue(jckCurrentKong, false, null); 試試uj5u.com熱心網友回復:
System.Reflection.PropertyInfo info = type.GetProperty(key);
info.SetValue(obj, false, null);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/17933.html
標籤:C#
上一篇:使用vs,c#,asp.net,
