码迷,mamicode.com
首页 > 其他好文 > 详细

Type.GetField 修改类中私有字段。

时间:2015-05-08 12:39:18      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

上一篇Popup Bug中修改了SystemParameters类中静态只读属性MenuDropAlignment。

技术分享

                var t = typeof(SystemParameters);
                var field = t.GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
                field.SetValue(null, false);

  其中 _menuDropAlignment 为SystemParameters中的静态 私有字段。通过Type.GetField反射出该字段并进行修改。。

  

     这样SystemParameters类中的只读属性就得到了修改

 

Type.GetField 修改类中私有字段。

标签:

原文地址:http://www.cnblogs.com/m7777/p/4487192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!