Type.GetField 反射修改类中私有静态字段。

上一篇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类中的只读属性就得到了修改

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