UserControl
에는 자식이 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);
}
}
이 가능하므로 ISomeInterface
을 구현 MainUserControl
에서 모든 자식 UserControl
의 내용을 알아보십시오
이 고려 리플렉션을 통해 해당 인터페이스에서 메소드 (void SomeMethod()
)를 호출 하시겠습니까?
왜 당신이 생각 GetProperties를() 메소드는 재귀 적으로 내려 갈 것? 전체 컨트롤 계층이 아닌 유형의 속성을 열거합니다. 대신 Controls 컬렉션을 열거 해보십시오. –