【发布时间】:2014-11-15 13:26:46
【问题描述】:
我目前正在使用以下内容从程序集中读取控制器
Public Shared Function GetControllers() As List(Of Type)
' Go through all assemblies referenced by the application and search for
' controllers and controller factories.
Dim controllerTypes As New List(Of Type)()
Dim Assemblies = AppDomain.CurrentDomain.GetAssemblies
For Each assembly As Reflection.Assembly In Assemblies
Dim typesInAsm As Type()
Try
typesInAsm = assembly.GetTypes()
Catch ex As Reflection.ReflectionTypeLoadException
typesInAsm = ex.Types
End Try
controllerTypes.AddRange(typesInAsm.Where(AddressOf IsControllerType))
Next
Return controllerTypes
End Function
然后我刚刚填充的列表用于读取所有操作,现在我正在尝试过滤掉具有 HTTPPost 的操作。
Public Shared Sub GetActionMethods(Controllers As List(Of Type))
For Each y In Controllers
Dim selector = New ActionMethodSelector(y)
Dim allValidMethods As New List(Of Reflection.MethodInfo)()
allValidMethods.AddRange(selector.AliasedMethods)
allValidMethods.AddRange(selector.NonAliasedMethods.SelectMany(Function(g) g))
Dim z = allValidMethods.ToArray()
Next
End Sub
问题是我不知道如何设置通过 linq 执行此操作的位置。我尝试了各种方法,但总是得到一个空列表。
Dim k = (From o As Reflection.MethodInfo In allValidMethods
Select o).ToArray
【问题讨论】:
标签: .net asp.net-mvc vb.net linq asp.net-mvc-5