我有一个UserControl有几个孩子UserControl的,那些UserControl有孩子用户控件的。
考虑一下:
MainUserControl
TabControl
TabItem
UserControl
UserControl
UserControl : ISomeInterface
TabItem
UserControl
UserControl
UserControl : ISomeInterface
TabItem
UserControl
UserControl
UserControl : ISomeInterface
TabItem
UserControl
UserControl
UserControl : ISomeInterface
这是我到目前为止所拥有的,但没有找到ISomeInterface:
PropertyInfo[] properties = MainUserControl.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
if (typeof(ISomeInterface).IsAssignableFrom(property.PropertyType))
{
property.GetType().InvokeMember("SomeMethod", BindingFlags.InvokeMethod, null, null, null);
}
}
是否有可能通过反射UserControl从MainUserControl该实现中找到所有 child 并在该接口上ISomeInterface调用方法( )?void SomeMethod()