C# 如何获取表单上的所有bindingsources

C# 如何获取表单上的所有bindingsources,c#,winforms,bindingsource,C#,Winforms,Bindingsource,我有一个基本表单,上面有一个BindingSource。我有一个从基表单继承的第二个表单,第二个表单还有5个绑定源 我想得到第二种形式(即6)的绑定源列表 因此,在基本表单的OnLoad中,我首先尝试: var list = this.Controls.OfType<BindingSource>(); 它还返回相同的bindingsource 在基本表单的OnLoad中执行上述操作应该可以,因为我可以获得第二个表单的所有控件 然而,我似乎无法获得第二种形式的绑定源 那么,列出它们的

我有一个基本表单,上面有一个
BindingSource
。我有一个从基表单继承的第二个表单,第二个表单还有5个绑定源

我想得到第二种形式(即6)的绑定源列表

因此,在基本表单的
OnLoad
中,我首先尝试:

var list = this.Controls.OfType<BindingSource>();
它还返回相同的bindingsource

在基本表单的
OnLoad
中执行上述操作应该可以,因为我可以获得第二个表单的所有控件

然而,我似乎无法获得第二种形式的绑定源

那么,列出它们的正确方法是什么呢?

使用来自的答案,接受的答案返回了一些控件,因此我添加了对Name属性的检查(这些组件在运行时没有):

private IEnumerable枚举组件(){
从GetType()中的字段返回。GetFields(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
其中typeof(Component).IsAssignableFrom(field.FieldType)
let component=(component)field.GetValue(this)
其中组件!=null
其中component.GetType().GetProperty(“名称”)==null
选择组件;
}
var List = (from Component bs in this.components.Components
            where bs is BindingSource
            select bs);
private IEnumerable<Component> EnumerateComponents() {
  return from field in GetType().GetFields(
              BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
         where typeof(Component).IsAssignableFrom(field.FieldType)
         let component = (Component)field.GetValue(this)
         where component != null
         where component.GetType().GetProperty("Name") == null
         select component;
}