ben kontrol hiyerarşisi dümdüz ve ardından filtreler uygulamak için bir uzantısı yöntemi kullanmak, böylece kendi özyinelemeli yöntemi kullanarak bu.
varsayım:
yöntem bu jenerik özyinelemeli yöntemini kullanın
//Returns all controls of a certain type in all levels:
public static IEnumerable<TheControlType> AllControls<TheControlType>(this Control theStartControl) where TheControlType : Control
{
var controlsInThisLevel = theStartControl.Controls.Cast<Control>();
return controlsInThisLevel.SelectMany(AllControls<TheControlType>).Concat(controlsInThisLevel.OfType<TheControlType>());
}
//(Another way) Returns all controls of a certain type in all levels, integrity derivation:
public static IEnumerable<TheControlType> AllControlsOfType<TheControlType>(this Control theStartControl) where TheControlType : Control
{
return theStartControl.AllControls().OfType<TheControlType>();
}
Lütfen bir kod örneği verebilir misiniz? – abatishchev
emin, paylaşım için, kod sayesinde kodun –
Gerçekten güzel bir parça eklendi! –