创建类的句柄财产
是否可以为类的属性创建一个句柄(或跟踪句柄)?例如,
System::Windows::Forms::CheckBox^ Box = gcnew System::Windows::Forms::CheckBox()
我想创建 Box 的 Checked 属性的句柄,并使用它来访问和修改该属性。
Would it be possible to create a handle ( or a tracking handle ) to a class' property ? For instance,
System::Windows::Forms::CheckBox^ Box = gcnew System::Windows::Forms::CheckBox()
I'd like to create a handle to Box's Checked property and use it to access and modify the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性只不过是 set/get 方法的语法糖,据我所知,没有办法捕获对属性的任何类型的引用(我想类似于绑定方法)。
我能想到的最好的解决方法(需要 VS2010)是传递几个 lambda:
编辑(因为你没有 VS2010):
你当然可以恢复到编写专用类的更巴洛克惯例:
如果有人问你 C++ lambda 有什么用处,那么很难跳过这个例子。
Properties are little more than syntactic sugar for set/get methods, and there is, AFAIK, no way to capture any kind of reference to one (something akin to a bound Method, I suppose).
The best workaround I can think of, which requires VS2010, is to pass a couple of lambdas around:
EDIT (since you don't have VS2010):
You can of course revert to the rather more baroque convention of writing a special-purpose class:
If anyone ever asks you what C++ lambdas are good for, it's hard to go past this example.