如何获取某些元数据的私有字段的值?
我正在使用名为 DevExpress.Xpo 的 NuGet 包,其 DataStorePool 类有一个名为 connections 的私有 int。我需要以某种方式在另一个类中使用它的值,但 DataStorePool 类被锁定为“元数据”,因此我无法将 int 设置为 public 也无法创建方法返回它。我该如何获取 int 的值?
I'm using a NuGet Package called DevExpress.Xpo and its DataStorePool class has a private int called connections. I need to somehow use its value in another class, but the DataStorePool class is locked as "metadata", so I can't set the int to public nor create a method that returns it. What can I do to obtain the value of the int?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个扩展方法来执行此操作。
它可以看起来像这样:
以及创建它的方式:
或者
您可以使用 BindingFlags.NonPublic 和 BindingFlags.Instance 标志
或
您可以在此处阅读如何使用反射获取它
You could create an extension method to do it.
It can look like that:
And the way to create it:
OR
You can use BindingFlags.NonPublic and BindingFlags.Instance flags
OR
You could read how to get it with using reflection here