开发者

How to get the value of non public member

How to get the value of non public member of the OPCGr开发者_C百科oup 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:

  • They don't want you to access it, at least not directly.
  • The implementation could change at any time, and your code should keep working.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜