使用反射获取基类的受保护属性值

编程入门 行业动态 更新时间:2024-10-25 14:29:29
本文介绍了使用反射获取基类的受保护属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道是否可以访问位于该对象的基类中并且是私有的ConfigurationId属性的值.我试图倒霉没有运气.

I would like to know if it is possible to access the value of the ConfigurationId property which is located in the base class of the object and it's private. I have tried to do it with reflection with no luck.

推荐答案

要访问ConfigurationId属性,我使用了以下代码:

To access ConfigurationId property i have used following code:

SubsetController controller = new SubsetController(new CConfigRepository(new FakeDataContextRepository())); var myBaseClassProtectedProperty= controller.GetType().BaseType .GetProperty("CCITenderInfo", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(controller); var myProtectedProperty = CCITenderInfo.GetType() .GetProperty("ConfigurationId", BindingFlags.Public | BindingFlags.Instance) .GetValue(myBaseClassProtectedProperty);

更多推荐

使用反射获取基类的受保护属性值

本文发布于:2023-11-12 11:43:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581408.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:反射   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!