本文整理匯總了VB.NET中System.Diagnostics.Switch類的典型用法代碼示例。如果您正苦於以下問題:VB.NET Switch類的具體用法?VB.NET Switch怎麽用?VB.NET Switch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Switch類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1:
' The following are possible values for the new switch.
Public Enum MethodTracingSwitchLevel
Off = 0
EnteringMethod = 1
ExitingMethod = 2
Both = 3
End Enum 'MethodTracingSwitchLevel
示例2: MyMethodTracingSwitch
Public Class MyMethodTracingSwitch
Inherits Switch
Protected outExit As Boolean
Protected outEnter As Boolean
Protected myLevel As MethodTracingSwitchLevel
Public Sub New(displayName As String, description As String)
MyBase.New(displayName, description)
End Sub
Public Property Level() As MethodTracingSwitchLevel
Get
Return myLevel
End Get
Set
SetSwitchSetting(CInt(value))
End Set
End Property
Protected Sub SetSwitchSetting(value As Integer)
If value < 0 Then
value = 0
End If
If value > 3 Then
value = 3
End If
myLevel = CType(value, MethodTracingSwitchLevel)
outEnter = False
If value = CInt(MethodTracingSwitchLevel.EnteringMethod) Or _
value = CInt(MethodTracingSwitchLevel.Both) Then
outEnter = True
End If
outExit = False
If value = CInt(MethodTracingSwitchLevel.ExitingMethod) Or _
value = CInt(MethodTracingSwitchLevel.Both) Then
outExit = True
End If
End Sub
Public ReadOnly Property OutputExit() As Boolean
Get
Return outExit
End Get
End Property
Public ReadOnly Property OutputEnter() As Boolean
Get
Return outEnter
End Get
End Property
End Class
示例3: Class1
Public Class Class1
' Create an instance of MyMethodTracingSwitch.
Private Shared mySwitch As New _
MyMethodTracingSwitch("Methods", "Trace entering and exiting method")
Public Shared Sub Main()
' Add the console listener to see trace messages as console output
Trace.Listeners.Add(New ConsoleTraceListener(True))
Debug.AutoFlush = True
' Set the switch level to both enter and exit
mySwitch.Level = MethodTracingSwitchLevel.Both
' Write a diagnostic message if the switch is set to entering.
Debug.WriteLineIf(mySwitch.OutputEnter, "Entering Main")
' Insert code to handle processing here...
' Write another diagnostic message if the switch is set to exiting.
Debug.WriteLineIf(mySwitch.OutputExit, "Exiting Main")
End Sub
End Class