如何获得非公众成员的价值 [英] How to get the value of non public member

查看:38
本文介绍了如何获得非公众成员的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#中的OPCDA.NET获取OPCGroup的非公共成员的价值

How to get the value of non public member of the OPCGroup using OPCDA.NET in C#

private void DataChangeHandler(object sender, DataChangeEventArgs e)
{
   try
   {
       object obj = sender;
       OpcGroup grp = (OpcGroup)sender; // I want the OPCgroup non public member value

       if (InvokeRequired)
       {
           BeginInvoke(new DataChangeEventHandler(DataChangeHandler), 
                       new object[] { sender, e });
           //return;
       }
       if (parameter.X == 0)
       {
           parameter.X = 1;
           Thread th = new Thread(param.update);
           th.Start(e);
       }
   }
   catch(OPCException ) { }
}

推荐答案

您不应尝试使用非公开成员.如果代码作者将其隐藏,则应假定:

You shouldn't try to use non-public members. If the author of the code has hidden it, you should assume that:

  • 他们不希望您访问它,至少不希望直接访问它.
  • 实现可能随时更改,并且您的代码应保持正常运行.

可以使用反射来访问非公共成员(假设在执行时具有适当的权限),但是如果可能的话,我强烈建议您不要这样做.

You can use reflection to access non-public members (assuming appropriate permissions at execution time) but I would highly discourage you from doing so if possible.

这篇关于如何获得非公众成员的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆