您的位置: 盘锦资讯网 > 健康

获取执行代码所处环境的信息

发布时间:2019-09-13 19:54:06

现在做一个方法运行耗时测试类

Imports System.ComponentModel

Namespace uReflection

Public Class CurrentMethodInfo

Private gMethodInformation As currentMethodInformation

Public Sub Input(ByVal methodbase As System.Reflection.MethodBase)

gMethodInformation = New currentMethodInformation(methodbase)

End Sub

Public Sub Input(ByVal stackframe As System.Diagnostics.StackFrame)

gMethodInformation = New currentMethodInformation(stackframe)

End Sub

'下以为测试方法耗时用

Private gStopwatch As System.Diagnostics.Stopwatch

Private gIsCheck As Boolean

Private gUsetime As String

Public Property CheckRuntime() As Boolean

Get

Return gIsCheck

End Get

Set(ByVal value As Boolean)

If value <> gIsCheck Then

If value Then

gStopwatch = New System.Diagnostics.Stopwatch

End If

gIsCheck = value

End If

End Set

End Property

Public Sub Start()

If CheckRuntime Then gStopwatch.Start()

End Sub

Public Sub [Stop]()

If CheckRuntime Then

gStopwatch.Stop()

gUsetime = gStopwatch.Elapsed.ToString

gStopwatch.Reset()

End If

End Sub

Public Overrides Function ToString() As String

Dim b As New System.Text.StringBuilder

b.Append(appInformation.ToString)

b.Append(gMethodInformation.ToString)

If CheckRuntime Then

b.Append(System.Environment.NewLine)

b.AppendFormat("** 测试用时 :{0}", Me.gUsetime)

b.Append(System.Environment.NewLine)

b.AppendFormat("** 测试时间 :{0}", Now.ToString)

b.Append(System.Environment.NewLine)

End If

b.Append(New String("*"c, 80))

Return b.ToString

End Function

Private Class currentMethodInformation

Private gMethodbase As System.Reflection.MethodBase

Sub New(ByVal methodbase As System.Reflection.MethodBase)

gMethodbase = methodbase

End Sub

Sub New(ByVal stackFrame As System.Diagnostics.StackFrame)

gMethodbase = stackFrame.GetMethod

End Sub

_

Public ReadOnly Property AssemblyName() As String

Get

Return gMethodbase.DeclaringType.Assembly.GetName.Name

End Get

End Property

_

Public ReadOnly Property AssemblyVersion() As String

Get

Return gMethodbase.DeclaringType.Assembly.GetName.Version.ToString

End Get

End Property

_

Public ReadOnly Property TypeName() As String

Get

Return gMethodbase.DeclaringType.FullName

End Get

End Property

_

Public ReadOnly Property Name() As String

Get

Return gMethodbase.ToString

End Get

End Property

Public Overloads Function ToString() As String

Dim b As New System.Text.StringBuilder

b.Append(System.Environment.NewLine)

b.AppendFormat("** 程序集名称 :{0}", Me.AssemblyName)

b.Append(System.Environment.NewLine)

b.AppendFormat("** 程序集版本 :{0}", Me.AssemblyVersion)

b.Append(System.Environment.NewLine)

b.AppendFormat("** 类名 :{0}", Me.TypeName)

b.Append(System.Environment.NewLine)

b.AppendFormat("** 方法名 :{0}", Me.Name)

b.Append(System.Environment.NewLine)

Return b.ToString

End Function

End Class

查看本文来源

小孩便秘怎么办
幼儿流鼻血是什么原因
小孩消化不良吃什么药
儿童止咳化痰
猜你会喜欢的
猜你会喜欢的