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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值