[Extension Method][VB.NET]使用擴充方法過濾出組件內的特定類別
Module AssembleExtension <Extension()> _ Public Function GetTypes(ByVal asm As Assembly, ByVal filterTypeName As String, Optional ByVal includeSubClass As Boolean = False) As Type() Return GetTypes(asm, Type.GetType(filterTypeName), includeSubClass) End Function
<Extension()> _
Public Function GetTypes(ByVal asm As Assembly, ByVal filterType As Type, Optional ByVal includeSubClass As Boolean = False) As Type()
Dim linq = From t In asm.GetTypes Where t Is filterType OrElse (includeSubClass AndAlso t.IsSubclassOf(filterType)) Select t
Return linq.ToArray
End Function
End Module