.NET Reflection中如何从FieldInfo中获取实际的控件对象?
我需要使用反射从 C# 中的 fieldInfo 对象获取“控制”对象。
Control mainControl = Control.FromHandle(a_hWnd);
object oMainControlObject = mainControl;
FieldInfo[] fieldInfos = oMainControlObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
对于fieldInfos数组中的每个fieldInfo,我需要获取相应的控制对象。
我的尝试:
Control oControl = Control.FromHandle(fieldInfo.FieldHandle.Value);
Control oControl = (Control)FieldInfo.GetValue(mainControl)
第一个返回 NULL,第二个不允许我对上述语句进行类型转换以进行控制。
问候,
乌斯曼
I need to get the "control" object from the fieldInfo object in C# using reflection.
Control mainControl = Control.FromHandle(a_hWnd);
object oMainControlObject = mainControl;
FieldInfo[] fieldInfos = oMainControlObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
For each fieldInfo in the fieldInfos array, I need to get the corresponding control object.
My Attempts:
Control oControl = Control.FromHandle(fieldInfo.FieldHandle.Value);
Control oControl = (Control)FieldInfo.GetValue(mainControl)
The first one returns NULL and the second one is not allowing me to typecast the above statement to control.
Regards,
Usman
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想递归地遍历
Controls
集合。It sounds like you want to recursively iterate through the
Controls
collection.