通用所有控制方法
想不到更好的标题,所以appologies ..
我试图转换这个方法 ,它将检索一个窗体的所有子控件,作为扩展方法以及接受接口作为input。 到目前为止,我是最好的
public IEnumerable<Control> GetAll<T>(this Control control) where T : class { var controls = control.Controls.Cast<Control>(); return controls.SelectMany(ctrl => GetAll<T>(ctrl)) .Concat(controls) .Where(c => c is T); }  这工作正常,除了我需要添加OfType<T>()时调用它来访问其属性。 
例如(这个==表单)
 this.GetAll<IMyInterface>().OfType<IMyInterface>() 
 我努力使返回types转换为generics返回typesIEnumerable<T> ,所以我不必包含一个只返回相同结果但正确转换的OfType。 
任何人有任何build议?
  (将返回types更改为IEnumerable<T>会导致Concat抛出 
实例参数:无法从“System.Collections.Generic.IEnumerable
<T>”转换为“System.Linq.ParallelQuery<System.Windows.Forms.Control>”
 问题是, Concat也希望IEnumerable<T> – 不是IEnumerable<Control> 。 这应该工作,虽然: 
 public static IEnumerable<T> GetAll<T>(this Control control) where T : class { var controls = control.Controls.Cast<Control>(); return controls.SelectMany(ctrl => GetAll<T>(ctrl)) .Concat(controls.OfType<T>())); }