vb.net2008 指定类名和方法名进行测试用的工具

前端之家收集整理的这篇文章主要介绍了vb.net2008 指定类名和方法名进行测试用的工具前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
'全局变量

Private mAppPath As String = My.Application.Info.DirectoryPath & "\" & My.Application.Info.ProductName & ".exe"

'函数

Private Function FindAssemblyByName(ByVal className As String,ByVal methodName As String) As Object

Dim objAssembly As Assembly = Assembly.LoadFrom(mAppPath)
Dim types() As Type = objAssembly.GetTypes
Dim objResult As Object = Nothing
msbText = New StringBuilder
Dim j As Integer

For Each mtype As Type In types
If mtype.Name = className Then

Dim objMethodInfo As System.Reflection.MethodInfo = mtype.GetMethod(methodName)
If objMethodInfo Is Nothing Then
MsgBox("関数が存在しません または 権限が私有かもしれません")
Exit For
End If

Dim objAdapter As Object = Activator.CreateInstance(mtype)
Dim Param As ParameterInfo
Dim Params As ParameterInfo() = objMethodInfo.GetParameters()

If Params.Count > 0 Then
msbText.AppendLine("--引数リスト---------------")
End If

For Each Param In Params
j = j + 1
msbText.AppendLine("--引数[" & CStr(j) & "]--")
msbText.AppendLine("Param=" + Param.Name.ToString())
msbText.AppendLine(" Type=" + Param.ParameterType.ToString())
msbText.AppendLine(" Position=" + Param.Position.ToString())
msbText.AppendLine(" Optional=" + Param.IsOptional.ToString())
Next Param

If Not Params Is Nothing AndAlso Params.Count > 0 Then

Dim objs As Object = New Object()

ReDim objs(Params.Count - 1)

objs(0) = mDBConn

For i As Integer = 0 To Params.Count - 2
objs(i + 1) = mAryTextBox.Item(i)
Next

objResult = objMethodInfo.Invoke(objAdapter,objs)

Else
objResult = objMethodInfo.Invoke(objAdapter,Nothing)
End If

Exit For
End If
Next

Return objResult

End Function

原文链接:https://www.f2er.com/vb/260700.html

猜你在找的VB相关文章