//動態鏈接庫中ClsPublic類有一變量 private static string key="1111";
//下面通過反射的技術修改和獲取值
//設置key
public static void updatePalmKey(string key = "test") { BindingFlags flag = BindingFlags.Static | BindingFlags.NonPublic; FieldInfo f_key = typeof(ClsPublic).GetField("key", flag); f_key.SetValue(new ClsPublic(), key); } ////// 獲取key /// ///public static string getPalmKey() { BindingFlags flag = BindingFlags.Static | BindingFlags.NonPublic; FieldInfo f_key = typeof(ClsPublic).GetField("key", flag); object o = f_key.GetValue(new ClsPublic()); return o.ToString(); }
//反射獲取修改類中的屬性
class Test
{
public string StrTest {get; set;};
}
////// 獲取修改類中的屬性 /// ///public void GetAndSetProperty() { Test t = new Test();PropertyInfo p=t.GetType().GetProperty("StrTest");p.SetValue(p,"test"); }
////// 獲取key /// ///public static string getPalmKey() { BindingFlags flag = BindingFlags.Static | BindingFlags.NonPublic; FieldInfo f_key = typeof(ClsPublic).GetField("key", flag); object o = f_key.GetValue(new ClsPublic()); return o.ToString(); }