我有一些控件從一個通用的基類繼承,這個類實現了一個接口IMyInterface
。獲取使用Linq實現接口的控件?
到目前爲止,我嘗試:
var results = from c in this.Controls.Cast<Control>()
where c.GetType().GetInterfaces().Contains(typeof(IMyInterface))
select c as IMyInterface;
然而,上述不返回任何結果,即使它應該。
如何使用Linq獲取實現此接口的窗體上的控件列表?
'OfType'。 –