Skip to content

Commit dc67593

Browse files
authored
Use Generic Overloads in VB Code and minor cleanup (dotnet#12615)
* Use Generic Overloads in VB Code * Add missing test to improve coverage * Simplify some paths that can now be shortened due to changes in Global Imports
1 parent 5c09107 commit dc67593

File tree

11 files changed

+31
-21
lines changed

11 files changed

+31
-21
lines changed

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/ApplicationServices/ConsoleApplicationBase.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
4343
''' Returns the command line arguments for the current application.
4444
''' </summary>
4545
''' <remarks>
46-
''' This function differs from <see cref="System.Environment.GetCommandLineArgs"/>
46+
''' This function differs from <see cref="Environment.GetCommandLineArgs"/>
4747
''' in that the path of the executing file (the 0th entry) is omitted from
4848
''' the returned collection
4949
''' </remarks>

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Audio.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Namespace Microsoft.VisualBasic.Devices
5555
Private Sub Play(sound As Media.SoundPlayer, mode As AudioPlayMode)
5656

5757
Debug.Assert(sound IsNot Nothing, "There's no SoundPlayer")
58-
Debug.Assert([Enum].IsDefined(GetType(AudioPlayMode), mode), "Enum value is out of range")
58+
Debug.Assert([Enum].IsDefined(mode), "Enum value is out of range")
5959

6060
' Stopping the sound ensures it's safe to dispose it. This could happen when we change the value of _Sound below
6161
_sound?.Stop()

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/ComputerInfo.InternalMemoryStatus.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Namespace Microsoft.VisualBasic.Devices
1111
''' Calls GlobalMemoryStatusEx and returns the correct value.
1212
''' </summary>
1313
Private NotInheritable Class InternalMemoryStatus
14-
Private _memoryStatusEx As NativeMethods.MEMORYSTATUSEX
14+
Private _memoryStatusEx As MEMORYSTATUSEX
1515

1616
Friend Sub New()
1717
End Sub
@@ -49,7 +49,7 @@ Namespace Microsoft.VisualBasic.Devices
4949
#Enable Warning IDE0049
5050

5151
Private Sub Refresh()
52-
_memoryStatusEx = New NativeMethods.MEMORYSTATUSEX
52+
_memoryStatusEx = New MEMORYSTATUSEX
5353
_memoryStatusEx.Init()
5454
If Not NativeMethods.GlobalMemoryStatusEx(_memoryStatusEx) Then
5555
Throw ExceptionUtils.GetWin32Exception(SR.DiagnosticInfo_Memory)

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Helpers/FileSystemUtils.vb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
3232

3333
' DirectoryInfo.GetFiles and GetDirectories call FindFirstFile which resolves 8.3 path.
3434
' Get the DirectoryInfo (user must have code permission or access permission).
35-
Dim dInfo As New IO.DirectoryInfo(FileIO.FileSystem.GetParentPath(fullPath))
35+
Dim dInfo As New DirectoryInfo(FileIO.FileSystem.GetParentPath(fullPath))
3636

3737
If IO.File.Exists(fullPath) Then
3838
Debug.Assert(dInfo.GetFiles(IO.Path.GetFileName(fullPath)).Length = 1, "Must found exactly 1")
@@ -50,15 +50,15 @@ Namespace Microsoft.VisualBasic.CompilerServices
5050
' or indicate that caller does not have enough permission and should get back the 8.3 path.
5151
If TypeOf ex Is ArgumentException OrElse
5252
TypeOf ex Is ArgumentNullException OrElse
53-
TypeOf ex Is IO.PathTooLongException OrElse
53+
TypeOf ex Is PathTooLongException OrElse
5454
TypeOf ex Is NotSupportedException OrElse
55-
TypeOf ex Is IO.DirectoryNotFoundException OrElse
55+
TypeOf ex Is DirectoryNotFoundException OrElse
5656
TypeOf ex Is SecurityException OrElse
5757
TypeOf ex Is UnauthorizedAccessException Then
5858

5959
Debug.Assert(Not (TypeOf ex Is ArgumentException OrElse
6060
TypeOf ex Is ArgumentNullException OrElse
61-
TypeOf ex Is IO.PathTooLongException OrElse
61+
TypeOf ex Is PathTooLongException OrElse
6262
TypeOf ex Is NotSupportedException), "These exceptions should be caught above")
6363

6464
Return fullPath
@@ -149,8 +149,8 @@ Namespace Microsoft.VisualBasic.CompilerServices
149149
''' </summary>
150150
''' <param name="path">The path to be normalized.</param>
151151
''' <returns>The normalized path.</returns>
152-
''' <exception cref="IO.Path.GetFullPath">
153-
''' <see cref="IO.Path.GetFullPath"/> for possible exceptions.
152+
''' <exception cref="Path.GetFullPath">
153+
''' <see cref="Path.GetFullPath"/> for possible exceptions.
154154
''' </exception>
155155
''' <remarks>
156156
''' Keep this function since we might change the implementation / behavior later.

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Helpers/NativeMethods.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
127127
#Enable Warning IDE1006
128128

129129
Friend Sub Init()
130-
dwLength = CType(Marshal.SizeOf(GetType(MEMORYSTATUSEX)), UInt32)
130+
dwLength = CType(Marshal.SizeOf(Of MEMORYSTATUSEX)(), UInt32)
131131
End Sub
132132

133133
End Structure

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Helpers/NativeTypes.SECURITY_ATTRIBUTES.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
1414
Implements IDisposable
1515

1616
Friend Sub New()
17-
nLength = Marshal.SizeOf(GetType(SECURITY_ATTRIBUTES))
17+
nLength = Marshal.SizeOf(Of SECURITY_ATTRIBUTES)()
1818
End Sub
1919

2020
Public nLength As Integer

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Logging/FileLogTraceListener.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ Namespace Microsoft.VisualBasic.Logging
878878
outBuilder.Append($"{source}{Delimiter}")
879879

880880
' eventType
881-
outBuilder.Append($"{[Enum].GetName(GetType(TraceEventType), eventType)}{Delimiter}")
881+
outBuilder.Append($"{[Enum].GetName(eventType)}{Delimiter}")
882882

883883
' id
884884
outBuilder.Append(FormattableString.Invariant($"{id}{Delimiter}"))

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/FileSystemProxy.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ Namespace Microsoft.VisualBasic.MyServices
653653
''' </param>
654654
''' <param name="fileWildcards">The search patterns to use for the file name ("*.*")</param>
655655
''' <returns>A string array containing the files that match the search condition.</returns>
656-
''' <exception cref="System.ArgumentNullException">
656+
''' <exception cref="ArgumentNullException">
657657
''' <paramref name="directory"/> is Nothing or an empty string.
658658
''' </exception>
659659
''' <exception cref="ArgumentException">

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/Internal/ProgressDialog.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
2929
Private Const WS_THICKFRAME As Integer = &H40000
3030

3131
'Required by the Windows Form Designer
32-
Private ReadOnly _components As System.ComponentModel.IContainer
32+
Private ReadOnly _components As IContainer
3333

3434
' Indicates whether or not the user has canceled the copy
3535
Private _canceled As Boolean
@@ -121,7 +121,7 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
121121
'Do not modify it using the code editor.
122122
<DebuggerStepThrough()>
123123
Private Sub InitializeComponent()
124-
Dim resources As New System.ComponentModel.ComponentResourceManager(GetType(ProgressDialog))
124+
Dim resources As New ComponentResourceManager(GetType(ProgressDialog))
125125
LabelInfo = New Label
126126
ProgressBarWork = New ProgressBar
127127
ButtonCloseDialog = New Button

src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/SecurityAttributesTests.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
1313
<WinFormsFact>
1414
Public Sub SECURITY_ATTRIBUTES_New_Success()
1515
Using securityAttributes As New SECURITY_ATTRIBUTES
16-
securityAttributes.nLength.Should.Be(Marshal.SizeOf(GetType(SECURITY_ATTRIBUTES)))
16+
securityAttributes.nLength.Should.Be(Marshal.SizeOf(Of SECURITY_ATTRIBUTES)())
1717
End Using
1818
End Sub
1919

0 commit comments

Comments
 (0)