在属性上触发一个事件/功能? (C#) [英] Firing an event / function on a property? (C#)

查看:142
本文介绍了在属性上触发一个事件/功能? (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用,我不能编辑类,它有一个属性(一个布尔值),其中,这将是很好当它改变时被告知,我不能编辑属性获取或设置为我导入类从一个.dll(我没有$ C $下)。

如何创建当特性改变所触发的事件/功能?

其他
它仅是在其自己的类发生变化,直接到底层的私有变量。

例如。

 私人布尔m_MyValue = FALSE;

公共BOOL myvalue的
  {
  {返回m_MyValue; }
  }

私人无效SomeFunction()
  {
  m_MyValue = TRUE;
  }
 

解决方案

您不能,基本上......不是没有使用类似的调试器API注入code的执行时间和修改IL原库(和我不建议任何的解决方案,除了别的它可能违反了图书馆的许可证)

基本上如果一个属性不支持通知,它不支持通知。你应该寻找接近你的问题的不同方式。 (可否民意调查工作,例如?)

I am using a class that I cannot edit, it has a property (a boolean) of which it would be nice to be informed when it changes, I can't edit the properties get or set as I am importing the class from a .dll (which I don't have the code for).

How do I create an event/function that is fired when the property is changed?

Additional
It is only changed within its own class, directly to the underlying private variable.

E.g.

private bool m_MyValue = false;

public bool MyValue
  {
  get { return m_MyValue; }
  }

private void SomeFunction()
  {
  m_MyValue = true;
  }

解决方案

You can't, basically... not without using something like the debugger API to inject code at execution time and modifying the IL of the original library (and I'm not recommending either of those solutions; aside from anything else it may violate the licence of the library).

Basically if a property doesn't support notification, it doesn't support notification. You should look for a different way of approaching your problem. (Would polling work, for example?)

这篇关于在属性上触发一个事件/功能? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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