├── .editorconfig
├── .gitattributes
├── .github
└── workflows
│ └── CI.yml
├── .gitignore
├── CSharpToVB.Tests
├── CSharpToVB.Tests.vbproj
├── CodeCoverage.cmd
├── CoverletArgs.runsettings
├── Helpers
│ ├── ConverterTestBase.vb
│ ├── FormattingTestBase.vb
│ ├── Portable
│ │ ├── AssertEx.vb
│ │ └── MarkedSource
│ │ │ └── MarkupTestFile.vb
│ └── VisualBasicFormattingTestBase.vb
├── My Project
│ ├── Application.Designer.vb
│ └── Application.myapp
└── Tests
│ ├── CSharpToVB
│ ├── ExpressionTests.vb
│ ├── MemberTests.vb
│ ├── SpecialConversionTests.vb
│ ├── StatementTests.vb
│ ├── SymbolRenameTests.vb
│ ├── TypeCastTests.vb
│ └── XMLDocumentCommentTest.vb
│ ├── CodeConverter
│ ├── NamespaceLevelTests.vb
│ └── TestWorkspace.vb
│ ├── ConvertDirectories
│ ├── FastTests.vb
│ ├── Over1MinuteTests.vb
│ ├── SlowerSpeedTests.vb
│ ├── SlowestSpeedTests.vb
│ ├── TestSupport.vb
│ └── TestUtilities.vb
│ ├── DictionaryLoadSave
│ └── LoadSaveDictionaryTests.vb
│ ├── Issues
│ └── IssuesTests.vb
│ ├── MSCoreReference
│ ├── MSCoreReferenceTest.vb
│ └── ProgressReportTests.vb
│ └── ProjectFile
│ └── SDKFileConvertTest.vb
├── CSharpToVB.sln
├── CSharpToVB.sln.DotSettings
├── CSharpToVB
├── App.config
├── ApplicationEvents.vb
├── Assets
│ ├── DarkModeColorDictionary.csv
│ └── LightModeColorDictionary.csv
├── CSharpToVB.vbproj
├── CSharpToVB.vbproj.DotSettings
├── CSharpToVB.vbproj.vsspell
├── ClassificationSupport
│ ├── ClassificationNameStrings.vb
│ ├── ColorDescriptor.vb
│ ├── ColorSelector.vb
│ ├── ColorizeSupport.vb
│ ├── Csv_DarkModeColorDictionary.vb
│ ├── Csv_LightModeColorDictionary.vb
│ └── RangeSupport.vb
├── ColorModeSupport
│ ├── DarkColorTable.vb
│ ├── DarkMode.vb
│ └── ThemeSupport.vb
├── Controls
│ ├── ComboBoxEx.vb
│ ├── LineNumberItem.vb
│ ├── LineNumbersForRichTextBox.Designer.vb
│ ├── LineNumbersForRichTextBox.vb
│ ├── PanelEx.vb
│ ├── ToolStripCheckBox.Designer.vb
│ ├── ToolStripCheckBox.vb
│ ├── ToolStripComboBoxEx.vb
│ ├── ToolStripTextProgressBar.Designer.vb
│ ├── ToolStripTextProgressBar.vb
│ └── WindowsMessageIDs.vb
├── Extensions
│ ├── FilePathExtensions.vb
│ ├── MenuExtensions.vb
│ ├── RichTextBoxExtensions.vb
│ ├── SpecializedCollection.vb
│ └── StringExtensions.vb
├── Forms
│ ├── AboutBox1.Designer.vb
│ ├── AboutBox1.resx
│ ├── AboutBox1.vb
│ ├── Form1.Designer.vb
│ ├── Form1.resx
│ ├── Form1.vb
│ ├── IgnoreFilesWithErrorsListDialog.Designer.vb
│ ├── IgnoreFilesWithErrorsListDialog.resx
│ ├── IgnoreFilesWithErrorsListDialog.vb
│ ├── OptionsDialog.Designer.vb
│ ├── OptionsDialog.resx
│ ├── OptionsDialog.vb
│ ├── SplashScreen1.Designer.vb
│ ├── SplashScreen1.resx
│ └── SplashScreen1.vb
├── Icons
│ ├── CStoVB.ico
│ └── NotificationAlert_16x.ico
├── Images
│ ├── AboutBox.png
│ ├── AboutBoxDark.png
│ ├── AdvancedView.png
│ ├── AdvancedViewDark.png
│ ├── Copy.png
│ ├── CopyDark.png
│ ├── Cut.png
│ ├── CutDark.png
│ ├── Exit.png
│ ├── ExitDark.png
│ ├── FeedbackSmile_16x.png
│ ├── FeedbackSmile_16xDark.png
│ ├── FindNext.png
│ ├── FindNextDark.png
│ ├── NotificationAlertGray_16x.png
│ ├── NotificationAlertRed_16x.png
│ ├── NotificationAlert_16x.png
│ ├── OpenFile.png
│ ├── OpenFileDark.png
│ ├── OpenProjectFolder.png
│ ├── OpenProjectFolderDark.png
│ ├── Paste.png
│ ├── PasteDark.png
│ ├── Redo.png
│ ├── RedoDark.png
│ ├── ScreenShot.jpg
│ ├── SelectAll.png
│ ├── SelectAllDark.png
│ ├── Snippet.png
│ ├── SnippetDark.png
│ ├── Undo.png
│ └── UndoDark.png
├── My Project
│ ├── Application.Designer.HighDpi.vb
│ ├── Application.Designer.vb
│ ├── Application.myapp
│ ├── Resources.Designer.vb
│ ├── Resources.resx
│ ├── Settings.Designer.vb
│ ├── Settings.settings
│ └── app.manifest
├── SupportClasses
│ ├── MyListItem.vb
│ ├── NumberedListItem.vb
│ ├── ProcessingStats.vb
│ └── Range.vb
└── Utilities
│ ├── BrowserUtilities.vb
│ ├── Compile.vb
│ ├── ConvertProjectFileUtilities.vb
│ ├── ConvertSolutionFileUtilities.vb
│ ├── LoadBufferSupport.vb
│ ├── ProcessDirectoriesUtilities.vb
│ ├── ProcessFileUtilities.vb
│ ├── ProcessProjectUtilities.vb
│ ├── TSToolBaseSupport.vb
│ ├── TargetFrameworkUtilities.vb
│ └── VisualStudioFileUtilities.vb
├── CodeConverter
├── CSharpToVBConverter
│ └── CSharpToVBVisitors
│ │ ├── ArgumentListVisitor.vb
│ │ ├── AttributesVisitor.vb
│ │ ├── DeclarationVisitor.vb
│ │ ├── DesignnationVisitor.vb
│ │ ├── EnsureUniquenessSupport.vb
│ │ ├── ExpressionVisitor.vb
│ │ ├── LinkVisitor.vb
│ │ ├── MethodBodyVisitor.vb
│ │ ├── NamesVisitor.vb
│ │ ├── NamespaceVisitor.vb
│ │ ├── NodesVisitor.vb
│ │ ├── ParametersVisitor.vb
│ │ ├── PatternVisitor.vb
│ │ ├── TypesModifiersVisitor.vb
│ │ └── XMLVisitor.vb
├── CodeConverter.vbproj
├── CodeConverter.vbproj.DotSettings
├── Extensions
│ ├── BlockExtensions.vb
│ ├── EnumExtensions.vb
│ ├── EnumerableExtensions.vb
│ ├── ExpressionSyntaxExtensions.vb
│ ├── ForEachExtensions.vb
│ ├── IndexClass.vb
│ ├── LanguageSyntaxNodeExtensions.vb
│ ├── NamedTypeSymbolExtensions.vb
│ ├── StatementExtensions.vb
│ ├── StringExtensions.vb
│ ├── SymbolExtensions.vb
│ ├── SymbolInfoExtensions.vb
│ ├── SyntaxExtensions.vb
│ ├── SyntaxKindExtensions.vb
│ ├── SyntaxNodeExtensions.vb
│ ├── SyntaxNodeVBExtensions.vb
│ ├── SyntaxTokenExtensions.vb
│ ├── SyntaxTreeExtensions.vb
│ ├── SyntaxTriviaListExtensions.vb
│ ├── TokenListExtensions.vb
│ ├── TriviaExtensions.vb
│ ├── TypeExtensions.vb
│ ├── TypeInfoExtensions.vb
│ ├── TypeSwitchExtensions.vb
│ ├── TypeSymbolExtensions.vb
│ └── VariableDeclarationExtensions.vb
├── SupportClasses
│ ├── CodeWithOptions.vb
│ ├── CommonConversions.vb
│ ├── ConversionResult.vb
│ ├── ConvertRequest.vb
│ ├── DefaultVBOptions.vb
│ ├── StatementHandling.vb
│ └── SymbolTableEntry.vb
└── Utilities
│ ├── AttributeAndModifierSupport.vb
│ ├── CSharpSyntaxFactory.vb
│ ├── ConvertLiteralSupport.vb
│ ├── DoConversion.vb
│ ├── ExceptionUtilities.vb
│ ├── IdentifierSupport.vb
│ ├── ParseUtilities.vb
│ ├── SharedReferences.vb
│ ├── StatementMarkerSupport.vb
│ ├── SyntaxNavigator.vb
│ ├── SyntaxNormalizer.vb
│ ├── TriviaListSupport.vb
│ ├── TypeConverterSupport.vb
│ ├── UnicodeNewline.vb
│ └── VisualBasicSyntaxFactory.vb
├── Directory.Build.props
├── License.txt
├── NuGet.config
├── ObjectPoolLibrary
├── ObjectPool.cs
└── ObjectPoolLibrary.csproj
├── ProgressReportLibrary
├── ProgressReport.vb
└── ProgressReportLibrary.vbproj
├── ReadMe.MD
├── Releases
└── C#ToVB5.0.7.0.zip
├── TestConsoleApp
├── AnalyzerAdditionalFile.vb
├── Program.vb
└── TestConsoleApp.vbproj
├── _global.json
└── csvGenerator
├── CsvGenerator.props
├── CsvGenerator.vb
├── ExceptionUtils.vb
├── InternalErrorException.vb
├── MalformedLineException.vb
├── Resoures
└── Common
│ └── SR.vb
├── TextFieldParser.vb
└── csvGenerator.vbproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/workflows/CI.yml:
--------------------------------------------------------------------------------
1 | on:
2 | push:
3 | branches: [ master ]
4 | pull_request:
5 | branches: [ master ]
6 |
7 | jobs:
8 | build:
9 | runs-on: windows-latest
10 |
11 | steps:
12 | - uses: actions/checkout@v2
13 | - name: Setup .NET
14 | uses: actions/setup-dotnet@v1
15 | with:
16 | dotnet-version: '6.0.x'
17 | - name: Install dependencies
18 | run: dotnet restore
19 | - name: Build solution and run tests
20 | run: dotnet test
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/CSharpToVB.Tests/CSharpToVB.Tests.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-windows
5 | true
6 | WindowsForms
7 | false
8 | en-US
9 | Paul M Cohen
10 | Travel By Paul
11 | Text
12 | On
13 | Off
14 | On
15 | https://github.com/paul1956/CSharpToVB
16 | git
17 | Copyright (c) .NET Foundation and Contributors
18 | true
19 | 5.0.0.19
20 | 5.0.0.19
21 | 5.0.0.19
22 | CSharp To VB Tests
23 |
24 |
25 |
26 |
27 | runtime; build; native; contentfiles; analyzers; buildtransitive
28 | all
29 |
30 |
31 | all
32 | runtime; build; native; contentfiles; analyzers; buildtransitive
33 |
34 |
35 |
36 | all
37 | runtime; build; native; contentfiles; analyzers; buildtransitive
38 |
39 |
40 | all
41 | runtime; build; native; contentfiles; analyzers; buildtransitive
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | all
56 | runtime; build; native; contentfiles; analyzers; buildtransitive
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/CodeCoverage.cmd:
--------------------------------------------------------------------------------
1 | echo %time%
2 | Set MANUAL_TESTS=
3 | Set EnableRoslynTests="True"
4 | echo %EnableRoslynTests%
5 | dotnet --list-sdks --roll-forward
6 | Rem dotnet test --collect:"XPlat Code Coverage" --settings coverletArgs.runsettings
7 | Rem JSON
8 | dotnet test ./CSharpToVB.Tests.vbproj /p:CollectCoverage=true /p:CoverletOutputFormat=json /p:CoverletOutput=./TestResults/LastRun/Coverage.json /p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*,[xunit*]*,[Microsoft.DotNet.XUnitExtensions]*,[ProgressReportLibrary]*,[CSharpToVBApp]*,[ObjectPoolLibrary]*"
9 | Rem OpenCover
10 | Rem dotnet test ./CSharpToVB.Tests.vbproj /p:CollectCoverage=true /p:CoverletOutputFormat=OpenCover /p:CoverletOutput=./TestResults/LastRun/Coverage.OpenCover /p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*,[xunit*]*,[Microsoft.DotNet.XUnitExtensions]*,[ProgressReportLibrary]*,[CSharpToVBApp]*,[ObjectPoolLibrary]*"
11 | Rem Cobertura
12 | Rem dotnet test ./CSharpToVB.Tests.vbproj /p:CollectCoverage=true /p:CoverletOutputFormat=Cobertura /p:CoverletOutput=./TestResults/LastRun/Coverage.Cobertura /p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*,[xunit*]*,[Microsoft.DotNet.XUnitExtensions]*,[ProgressReportLibrary]*,[CSharpToVBApp]*,[ObjectPoolLibrary]*"
13 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/CoverletArgs.runsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | json
8 |
9 | [coverlet.*]*,[*]Coverlet.Core*,[xunit*]*,[Microsoft.DotNet.XUnitExtensions]*,[ProgressReportLibrary]*,[CSharpToVBApp]*,[HashLibrary]*
10 |
11 |
12 |
13 | Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute
14 |
15 |
16 |
17 | false
18 | false
19 | true
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Helpers/FormattingTestBase.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Collections.Immutable
6 | Imports System.Threading
7 | Imports Helpers.Portable
8 | Imports Microsoft.CodeAnalysis
9 | Imports Microsoft.CodeAnalysis.Formatting
10 | Imports Microsoft.CodeAnalysis.Options
11 | Imports Microsoft.CodeAnalysis.Text
12 | Imports Xunit
13 |
14 | Namespace Helpers
15 |
16 | Public MustInherit Class FormattingTestBase
17 |
18 | Protected Async Function AssertFormatAsync(expected As String,
19 | code As String,
20 | spans As ImmutableArray(Of TextSpan),
21 | language As String,
22 | Optional changedOptionSet As Dictionary(Of OptionKey, Object) = Nothing,
23 | Optional treeCompare As Boolean = True,
24 | Optional parseOptions As ParseOptions = Nothing) As Task
25 | Using workspace As New AdhocWorkspace()
26 | Dim project As Project = workspace.CurrentSolution.AddProject("Project", "Project.dll", language)
27 | If parseOptions IsNot Nothing Then
28 | project = project.WithParseOptions(parseOptions)
29 | End If
30 |
31 | Dim doc As Document = project.AddDocument("Document", SourceText.From(code))
32 |
33 | Dim tree As SyntaxTree = Await doc.GetSyntaxTreeAsync().ConfigureAwait(False)
34 |
35 | Dim options As OptionSet = workspace.Options
36 | If changedOptionSet IsNot Nothing Then
37 | For Each entry As KeyValuePair(Of OptionKey, Object) In changedOptionSet
38 | options = options.WithChangedOption(entry.Key, entry.Value)
39 | Next
40 | End If
41 |
42 | AssertFormat(workspace,
43 | expected,
44 | Await tree.GetRootAsync().ConfigureAwait(False),
45 | spans,
46 | options,
47 | Await doc.GetTextAsync().ConfigureAwait(False))
48 |
49 | ' format with node and transform
50 | Me.AssertFormatWithTransformation(workspace, expected, Await tree.GetRootAsync().ConfigureAwait(False), spans, options, treeCompare, parseOptions)
51 | End Using
52 | End Function
53 |
54 | Protected Sub AssertFormatWithTransformation(workspace As Workspace, expected As String, root As SyntaxNode, spans As IEnumerable(Of TextSpan), optionSet As OptionSet, treeCompare As Boolean, parseOptions As ParseOptions)
55 | Dim newRootNode As SyntaxNode = Formatter.Format(root, spans, workspace, optionSet, CancellationToken.None)
56 |
57 | Assert.Equal(expected, newRootNode.ToFullString())
58 |
59 | ' test doesn't use parsing option. add one if needed later
60 | Dim newRootNodeFromString As SyntaxNode = Me.ParseCompilation(expected, parseOptions)
61 | If treeCompare Then
62 | ' simple check to see whether two nodes are equivalent each other.
63 | Assert.[True](newRootNodeFromString.IsEquivalentTo(newRootNode))
64 | End If
65 | End Sub
66 |
67 | Protected MustOverride Function ParseCompilation(text As String, parseOptions As ParseOptions) As SyntaxNode
68 |
69 | Friend Shared Sub AssertFormat(workspace As Workspace, expected As String, root As SyntaxNode, spans As ImmutableArray(Of TextSpan), optionSet As OptionSet, sourceText As SourceText)
70 | Dim result As IList(Of TextChange) = Formatter.GetFormattedTextChanges(root, spans, workspace, optionSet)
71 | AssertResult(expected, sourceText, result)
72 | End Sub
73 |
74 | Friend Shared Sub AssertResult(expected As String, sourceText As SourceText, result As IList(Of TextChange))
75 | Dim actual As String = sourceText.WithChanges(result).ToString()
76 | EqualOrDiff(expected, actual)
77 | End Sub
78 |
79 | End Class
80 |
81 | End Namespace
82 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Helpers/Portable/AssertEx.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 | Imports System.Text
5 | Imports DiffPlex
6 | Imports DiffPlex.DiffBuilder
7 | Imports DiffPlex.DiffBuilder.Model
8 | Imports Xunit
9 |
10 | Namespace Helpers.Portable
11 |
12 | ''
13 | '' Assert style type to deal with the lack of features in xUnit's Assert type
14 | ''
15 | Public Module AssertEx
16 |
17 | ''
18 | '' Asserts that two strings are equal, and prints the difference between the two if they are not.
19 | ''
20 | '' The expected string. This is presented as the "baseline/before" side of the difference.
21 | '' The actual string. This is presented as the changed or "after" side in the difference.
22 | '' The message to precede the difference, if the values are not equal.
23 | Public Sub EqualOrDiff(expected As String, actual As String, Optional message As String = Nothing)
24 | If expected = actual Then
25 | Return
26 | End If
27 |
28 | Dim diffBuilder As New InlineDiffBuilder(New Differ())
29 | Dim diff As DiffPaneModel = diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace:=False)
30 | Dim messageBuilder As New StringBuilder()
31 | messageBuilder.AppendLine(
32 | If(String.IsNullOrEmpty(message),
33 | "Actual and expected values differ. Expected shown in baseline of difference:", message))
34 |
35 | For Each line As DiffPiece In diff.Lines
36 | Select Case line.Type
37 | Case ChangeType.Inserted
38 | messageBuilder.Append("+"c)
39 | Case ChangeType.Deleted
40 | messageBuilder.Append("-"c)
41 | Case Else
42 | messageBuilder.Append(" "c)
43 | End Select
44 |
45 | messageBuilder.AppendLine(line.Text)
46 | Next
47 |
48 | Assert.[True](False, messageBuilder.ToString())
49 | End Sub
50 |
51 | End Module
52 | End Namespace
53 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Helpers/VisualBasicFormattingTestBase.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 | Imports System.Collections.Immutable
5 | Imports Helpers.Portable.MarkedSource
6 | Imports Microsoft.CodeAnalysis
7 | Imports Microsoft.CodeAnalysis.Options
8 | Imports Microsoft.CodeAnalysis.Text
9 | Imports Microsoft.CodeAnalysis.VisualBasic
10 |
11 | Namespace Helpers
12 |
13 | Public NotInheritable Class VisualBasicFormattingTestBase
14 | Inherits FormattingTestBase
15 | Implements IDisposable
16 |
17 | Private ReadOnly _ws As Workspace
18 |
19 | Protected Overrides Function ParseCompilation(text As String, parseOptions As ParseOptions) As SyntaxNode
20 | Return SyntaxFactory.ParseCompilationUnit(text, options:=DirectCast(parseOptions, VisualBasicParseOptions))
21 | End Function
22 |
23 | Private Overloads Function AssertFormatAsync(expected As String,
24 | code As String,
25 | spans As ImmutableArray(Of TextSpan),
26 | Optional changedOptionSet As Dictionary(Of OptionKey, Object) = Nothing,
27 | Optional testWithTransformation As Boolean = False,
28 | Optional experimental As Boolean = False) As Task
29 |
30 | Dim parseOptions As New VisualBasicParseOptions(LanguageVersion.VisualBasic16, DocumentationMode.None)
31 | If experimental Then
32 | ' There are no experimental features at this time.
33 | ' parseOptions = parseOptions.WithExperimentalFeatures
34 | End If
35 |
36 | Return Me.AssertFormatAsync(expected, code, spans, LanguageNames.VisualBasic, changedOptionSet, testWithTransformation, parseOptions)
37 | End Function
38 |
39 | Friend Function AssertFormatSpanAsync(markupCode As String, expected As String) As Task
40 | Dim code As String = Nothing
41 | Dim spans As ImmutableArray(Of TextSpan) = Nothing
42 | GetSpans(markupCode, code, spans)
43 |
44 | Return Me.AssertFormatAsync(expected, code, spans)
45 | End Function
46 |
47 | Public Sub Dispose() Implements IDisposable.Dispose
48 | If _ws IsNot Nothing Then
49 | _ws.Dispose()
50 | End If
51 | End Sub
52 |
53 | End Class
54 |
55 | End Namespace
56 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 1
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/CSharpToVB/SymbolRenameTests.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Helpers
6 | Imports Xunit
7 |
8 | Namespace Tests.CSharpToVB
9 |
10 |
11 | Public Class SymbolRenameTests
12 | Inherits ConverterTestBase
13 |
14 |
15 | Public Shared Sub CSharpToVbSymbolRename()
16 | TestConversionCSharpToVisualBasic("public class ClashingNames
17 | {
18 | private string ab;
19 |
20 | void Test()
21 | {
22 | object aB = 5;
23 | int Ab = 7;
24 | }
25 |
26 | void Test2(int ab)
27 | {
28 | object aB = 5;
29 | int AB = 6;
30 | string s = nameof(AB);
31 | string s2 = nameof(ab);
32 | }
33 | }", "Public Class ClashingNames
34 |
35 | Private ab As String
36 |
37 | Private Sub Test()
38 | Dim aB1 As Object = 5
39 | Dim Ab2 As Integer = 7
40 | End Sub
41 |
42 | Private Sub Test2(ab As Integer)
43 | Dim aB1 As Object = 5
44 | Dim AB3 As Integer = 6
45 | Dim s As String = NameOf(AB3)
46 | Dim s2 As String = NameOf(ab)
47 | End Sub
48 | End Class")
49 | End Sub
50 |
51 | End Class
52 |
53 | End Namespace
54 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/CSharpToVB/XMLDocumentCommentTest.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Helpers
6 | Imports Xunit
7 |
8 | Namespace Tests.CSharpToVB
9 |
10 | Public Class XmlDocumentCommentTest
11 | Inherits ConverterTestBase
12 |
13 | Private Const CsharpCode As String = "// Licensed to the .NET Foundation under one or more agreements.
14 | // The .NET Foundation licenses this file to you under the MIT license.
15 | // See the LICENSE file in the project root for more information.
16 |
17 | using System.Collections.Immutable;
18 | using Microsoft.CodeAnalysis.CSharp.Extensions;
19 | using Microsoft.CodeAnalysis.CSharp.Syntax;
20 | using Microsoft.CodeAnalysis.Diagnostics;
21 | using Microsoft.CodeAnalysis.Diagnostics.PreferFrameworkType;
22 |
23 | namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.Analyzers
24 | {
25 | [DiagnosticAnalyzer(LanguageNames.CSharp)]
26 | internal class CSharpPreferFrameworkTypeDiagnosticAnalyzer :
27 | PreferFrameworkTypeDiagnosticAnalyzerBase
28 | {
29 | protected override ImmutableArray SyntaxKindsOfInterest =>
30 | ImmutableArray.Create(SyntaxKind.PredefinedType);
31 |
32 | ///
33 | /// every predefined type keyword except `void` can be replaced by its framework type in code.
34 | ///
35 | protected override bool IsPredefinedTypeReplaceableWithFrameworkType(PredefinedTypeSyntax node) =>
36 | node.Keyword.Kind() != SyntaxKind.VoidKeyword;
37 |
38 | protected override bool IsInMemberAccessOrCrefReferenceContext(ExpressionSyntax node) =>
39 | node.IsInMemberAccessContext() || node.InsideCrefReference();
40 |
41 | protected override string GetLanguageName() => LanguageNames.CSharp;
42 | }
43 | }
44 | "
45 |
46 | Private Const DesiredResult As String = "' Licensed to the .NET Foundation under one or more agreements.
47 | ' The .NET Foundation licenses this file to you under the MIT license.
48 | ' See the LICENSE file in the project root for more information.
49 | Option Explicit Off
50 | Option Infer On
51 | Option Strict Off
52 |
53 | Imports System.Collections.Immutable
54 | Imports Microsoft.CodeAnalysis.CSharp.Extensions
55 | Imports Microsoft.CodeAnalysis.CSharp.Syntax
56 | Imports Microsoft.CodeAnalysis.Diagnostics
57 | Imports Microsoft.CodeAnalysis.Diagnostics.PreferFrameworkType
58 |
59 | Namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.Analyzers
60 |
61 |
62 | Friend Class CSharpPreferFrameworkTypeDiagnosticAnalyzer
63 | Inherits PreferFrameworkTypeDiagnosticAnalyzerBase(Of SyntaxKind, ExpressionSyntax, PredefinedTypeSyntax)
64 |
65 | Protected Overrides ReadOnly Property SyntaxKindsOfInterest As ImmutableArray(Of SyntaxKind)
66 | Get
67 | Return ImmutableArray.Create(SyntaxKind.PredefinedType)
68 | End Get
69 | End Property
70 |
71 | '''
72 | ''' every predefined type keyword except `void` can be replaced by its framework type in code.
73 | '''
74 | Protected Overrides Function IsPredefinedTypeReplaceableWithFrameworkType(node As PredefinedTypeSyntax) As Boolean
75 | Return node.Keyword.Kind() <> SyntaxKind.VoidKeyword
76 | End Function
77 |
78 | Protected Overrides Function IsInMemberAccessOrCrefReferenceContext(node As ExpressionSyntax) As Boolean
79 | Return node.IsInMemberAccessContext() OrElse node.InsideCrefReference()
80 | End Function
81 |
82 | Protected Overrides Function GetLanguageName() As String
83 | Return LanguageNames.CSharp
84 | End Function
85 | End Class
86 | End Namespace
87 | "
88 |
89 |
90 | Public Shared Sub CSharpToVbMalformedDocumentComments()
91 | TestConversionCSharpToVisualBasic(CsharpCode, DesiredResult, includeOptions:=False)
92 | End Sub
93 |
94 | End Class
95 |
96 | End Namespace
97 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/CodeConverter/TestWorkspace.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports Microsoft.CodeAnalysis.Host
7 | Imports Microsoft.CodeAnalysis.Text
8 |
9 | Namespace Tests.CodeConverter
10 |
11 | Friend Class TestWorkspace
12 | Inherits Workspace
13 |
14 | Private Shared Shadows ReadOnly s_services As HostServices = Mef.MefHostServices.DefaultHost
15 |
16 | Public Sub New(Optional workspaceKind As String = "Test")
17 | MyBase.New(s_services, workspaceKind)
18 | End Sub
19 |
20 | Protected Overrides Sub ApplyDocumentTextChanged(id As DocumentId, text As SourceText)
21 | MyBase.ApplyDocumentTextChanged(id, text)
22 | Dim document As Document = Me.CurrentSolution.GetDocument(id)
23 | If document IsNot Nothing Then
24 | Me.OnDocumentTextChanged(id, text, PreservationMode.PreserveValue)
25 | End If
26 | End Sub
27 |
28 | Public Overrides Function CanApplyChange(feature As ApplyChangesKind) As Boolean
29 | Return True
30 | End Function
31 |
32 | Public Sub ChangeDocument(id As DocumentId, text As SourceText)
33 | Me.ApplyDocumentTextChanged(id, text)
34 | End Sub
35 |
36 | Public Sub Open(projectInfo As ProjectInfo)
37 | Dim sInfo As SolutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), Nothing, {projectInfo})
38 | Me.OnSolutionAdded(sInfo)
39 | End Sub
40 |
41 | End Class
42 |
43 | End Namespace
44 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/ConvertDirectories/TestSupport.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 | Imports System.Reflection
7 | Imports System.Threading
8 | Imports CSharpToVBApp
9 |
10 | Imports Microsoft.CodeAnalysis
11 | Imports Microsoft.CodeAnalysis.Emit
12 |
13 | Imports Xunit
14 |
15 | Namespace Tests.ConvertDirectories
16 |
17 | Public Module TestSupport
18 | Friend _lastFileProcessed As String
19 |
20 | '''
21 | ''' Return False to skip test
22 | '''
23 | Public ReadOnly Property EnableRoslynTests() As Boolean
24 | Get
25 | Return Directory.Exists(GetRoslynRootDirectory) AndAlso (Debugger.IsAttached OrElse Environment.GetEnvironmentVariable("EnableRoslynTests") IsNot Nothing)
26 | End Get
27 | End Property
28 |
29 | Friend Function TestProcessFileAsync(mainForm As Form1, pathWithFileName As String, targetDirectory As String, _0 As String, csPreprocessorSymbols As List(Of String), vbPreprocessorSymbols As List(Of KeyValuePair(Of String, Object)), optionalReferences() As MetadataReference, skipAutoGenerated As Boolean, isProjectConversion As Boolean, cancelToken As CancellationToken) As Task(Of Boolean)
30 | ' Save to TargetDirectory not supported
31 | Assert.True(String.IsNullOrWhiteSpace(targetDirectory))
32 | ' Do not delete the next line or the parameter it is needed by other versions of this routine
33 | _lastFileProcessed = pathWithFileName
34 | Using fs As FileStream = File.OpenRead(pathWithFileName)
35 | Dim requestToConvert As New ConvertRequest(mSkipAutoGenerated:=True, isProjectConversion, mProgress:=Nothing, mCancelToken:=cancelToken) With {
36 | .SourceCode = fs.GetFileTextFromStream()
37 | }
38 |
39 | Dim resultOfConversion As ConversionResult = ConvertInputRequest(requestToConvert, New DefaultVbOptions, csPreprocessorSymbols, vbPreprocessorSymbols, CSharpReferences(Assembly.Load("System.Windows.Forms").Location, optionalReferences).ToArray, reportException:=Nothing, mProgress:=Nothing)
40 | If resultOfConversion.ResultStatus = ConversionResult.ResultTriState.Failure Then
41 | Return Task.FromResult(False)
42 | End If
43 | Dim compileResult As (CompileSuccess As Boolean, EmitResult As EmitResult) = CompileVisualBasicString(stringToBeCompiled:=resultOfConversion.ConvertedCode, vbPreprocessorSymbols, DiagnosticSeverity.Error, resultOfConversion)
44 | If Not compileResult.CompileSuccess OrElse resultOfConversion.GetFilteredListOfFailures().Any Then
45 | Dim msg As String = If(compileResult.CompileSuccess, resultOfConversion.GetFilteredListOfFailures()(0).GetMessage, "Fatal Compile error")
46 | Throw New ApplicationException($"{pathWithFileName} failed to compile with error :{vbCrLf}{msg}")
47 | End If
48 | End Using
49 | Return Task.FromResult(True)
50 | End Function
51 |
52 | Public Async Function TestProcessDirectoryAsync(sourceDirectory As String) As Task(Of Boolean)
53 | Return Await ProcessDirectoryAsync(mainForm:=Nothing, sourceDirectory, targetDirectory:="", stopButton:=Nothing, listBoxFileList:=Nothing, sourceLanguageExtension:="cs", New ProcessingStats(""), AddressOf TestProcessFileAsync, CancellationToken.None).ConfigureAwait(continueOnCapturedContext:=True)
54 | End Function
55 |
56 | End Module
57 | End Namespace
58 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/ConvertDirectories/TestUtilities.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 | Imports System.Runtime.CompilerServices
7 | Imports System.Text
8 | Imports Microsoft.CodeAnalysis
9 | Imports Microsoft.CodeAnalysis.VisualBasic
10 | Imports Xunit
11 |
12 | Namespace Tests.ConvertDirectories
13 |
14 | Public Module TestUtilities
15 |
16 | Private ReadOnly s_lockRoslynRootDirectory As New Object
17 | Private _sRoslynRootDirectory As String = String.Empty
18 |
19 | Private Sub GetOccurrenceCount(kind As SyntaxKind, node As SyntaxNodeOrToken,
20 | ByRef actualCount As Integer)
21 | If node.IsKind(kind) Then
22 | actualCount += 1
23 | End If
24 | If node.IsToken Then
25 | Dim tk As SyntaxNodeOrToken = node
26 | For Each leadingTrivia As SyntaxTrivia In tk.GetLeadingTrivia()
27 | If leadingTrivia.IsKind(kind) Then
28 | actualCount += 1
29 | End If
30 | If leadingTrivia.HasStructure Then
31 | Dim leadingTriviaStructure As SyntaxNode = leadingTrivia.GetStructure
32 | GetOccurrenceCount(kind, leadingTriviaStructure, actualCount)
33 | End If
34 | Next
35 | For Each trailingTrivia As SyntaxTrivia In tk.GetTrailingTrivia()
36 | If trailingTrivia.IsKind(kind) Then
37 | actualCount += 1
38 | End If
39 | If trailingTrivia.HasStructure Then
40 | Dim trailingTriviaStructure As SyntaxNode = trailingTrivia.GetStructure
41 | GetOccurrenceCount(kind, trailingTriviaStructure, actualCount)
42 | End If
43 | Next
44 | End If
45 | For Each child As SyntaxNodeOrToken In node.ChildNodesAndTokens()
46 | GetOccurrenceCount(kind, child, actualCount)
47 | Next
48 | End Sub
49 |
50 | Friend Function HomogenizeEol(str As String) As String
51 | Dim sb As New StringBuilder()
52 | For index As Integer = 0 To str.Length - 1
53 | Dim ch As Char = str.Chars(index)
54 | Dim possibleNewline As Integer = GetDelimiterLength(ch, If(index + 1 < str.Length, str.Chars(index + 1), ControlChars.NullChar))
55 | If possibleNewline > 0 Then
56 | sb.AppendLine()
57 | If possibleNewline = 2 Then
58 | ' ReSharper disable once RedundantAssignment
59 | index += 1
60 | End If
61 | Else
62 | sb.Append(ch)
63 | End If
64 | Next index
65 | Return sb.ToString()
66 | End Function
67 |
68 | Public Function GetRoslynRootDirectory() As String
69 | SyncLock s_lockRoslynRootDirectory
70 | If String.IsNullOrWhiteSpace(_sRoslynRootDirectory) Then
71 | _sRoslynRootDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Source")
72 | If Not Directory.Exists(_sRoslynRootDirectory) Then
73 | Return ""
74 | End If
75 | _sRoslynRootDirectory = Path.Combine(_sRoslynRootDirectory, "Repos")
76 | If Not Directory.Exists(_sRoslynRootDirectory) Then
77 | Return ""
78 | End If
79 | _sRoslynRootDirectory = Path.Combine(_sRoslynRootDirectory, "Roslyn")
80 | If Not Directory.Exists(_sRoslynRootDirectory) Then
81 | Return ""
82 | End If
83 | End If
84 | End SyncLock
85 | Return _sRoslynRootDirectory
86 | End Function
87 |
88 |
89 | Public Function VerifyOccurrenceCount(tree As SyntaxTree, kind As SyntaxKind, expectedCount As Integer) As SyntaxTree
90 | Dim actualCount As Integer = 0
91 | GetOccurrenceCount(kind, tree?.GetRoot(), actualCount)
92 | Assert.Equal(expectedCount, actualCount)
93 | Return tree
94 | End Function
95 |
96 | End Module
97 | End Namespace
98 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/DictionaryLoadSave/LoadSaveDictionaryTests.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Drawing
6 | Imports System.IO
7 | Imports CSharpToVBApp
8 | Imports Xunit
9 |
10 | Namespace Tests.DictionaryLoadSave
11 |
12 | Public NotInheritable Class LoadSaveDictionaryTests
13 |
14 | Private ReadOnly _testThemeMappingDictionary As New Dictionary(Of String, ColorDescriptor)(StringComparer.OrdinalIgnoreCase) From {
15 | {ThemeDefaultColor, New ColorDescriptor(Color.White, Color.FromArgb(30, 30, 30))},
16 | {ThemeErrorColor, New ColorDescriptor(Color.FromArgb(0, 128, 128), Color.FromArgb(18, 32, 42))}}
17 |
18 | Private ReadOnly _resultDictionary As New Dictionary(Of String, ColorDescriptor)(StringComparer.OrdinalIgnoreCase)
19 |
20 |
21 | Public Sub VbDictionaryWriteTest()
22 | Dim filePath As String = Path.Combine(Path.GetTempPath, "TestColorDictionary.csv")
23 | WriteColorDictionaryToFile(filePath, _testThemeMappingDictionary)
24 | LoadColorDictionaryFromFile(filePath, _resultDictionary)
25 | Assert.Equal(_testThemeMappingDictionary.Count, _resultDictionary.Count)
26 | Assert.True(_resultDictionary.ContainsKey(ThemeDefaultColor))
27 | Assert.True(_testThemeMappingDictionary(ThemeDefaultColor).Equals(_resultDictionary(ThemeDefaultColor)))
28 | Assert.True(_resultDictionary.ContainsKey(ThemeErrorColor))
29 | Assert.True(_testThemeMappingDictionary(ThemeErrorColor) = _resultDictionary(ThemeErrorColor))
30 | File.Delete(filePath)
31 | End Sub
32 |
33 |
34 | Public Sub ClassificationStringToNameTest()
35 | Assert.Equal(NameOf(ThemeDefaultColor), "default".ClassificationStringToName())
36 | Assert.Equal(NameOf(ThemeErrorColor), "error".ClassificationStringToName())
37 | Assert.Equal(NameOf(NumericLiteral), "number".ClassificationStringToName())
38 | Assert.Equal(NameOf(String_VerbatimLiteral), "string - verbatim".ClassificationStringToName())
39 | Assert.Equal(NameOf(StringLiteral), "string".ClassificationStringToName())
40 |
41 | Assert.Equal(NameOf(Comment), "comment".ClassificationStringToName())
42 | Assert.Equal(NameOf(ExcludedCode), "excluded code".ClassificationStringToName())
43 | Assert.Equal(NameOf(Identifier), "identifier".ClassificationStringToName())
44 | Assert.Equal(NameOf(Keyword), "keyword".ClassificationStringToName())
45 | Assert.Equal(NameOf(ClassificationNameStrings.FunctionKeyword), "Function".ClassificationStringToName())
46 | Assert.Equal($"[{NameOf([Operator])}]", "operator".ClassificationStringToName())
47 |
48 | End Sub
49 |
50 |
51 | Public Sub ClassificationNameToStringTest()
52 | Assert.Equal(ClassificationNameToString(NameOf(ThemeDefaultColor)), "default")
53 | Assert.Equal(ClassificationNameToString(NameOf(ThemeErrorColor)), "error")
54 | Assert.Equal(ClassificationNameToString(NameOf(NumericLiteral)), "number")
55 | Assert.Equal(ClassificationNameToString(NameOf(String_VerbatimLiteral)), "string - verbatim")
56 | Assert.Equal(ClassificationNameToString(NameOf(StringLiteral)), "string")
57 |
58 | Assert.Equal(ClassificationNameToString(NameOf(Comment)), "comment")
59 | Assert.Equal(ClassificationNameToString(NameOf(ExcludedCode)), "excluded code")
60 | Assert.Equal(ClassificationNameToString(NameOf(Identifier)), "identifier")
61 | Assert.Equal(ClassificationNameToString(NameOf(Keyword)), "keyword")
62 | Assert.Equal(ClassificationNameToString(NameOf(ClassificationNameStrings.FunctionKeyword)), "function")
63 | Assert.Equal(ClassificationNameToString(NameOf([Operator])), "operator")
64 |
65 | End Sub
66 |
67 |
68 | Public Shared Sub VbTestRemoveNewLine()
69 | Dim originalString As String = "This is a 2 Line
70 | String"
71 | Assert.Equal(originalString.WithoutNewLines, "This is a 2 LineString")
72 | End Sub
73 |
74 | End Class
75 |
76 | End Namespace
77 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/MSCoreReference/MSCoreReferenceTest.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports Microsoft.CodeAnalysis.CSharp
7 | Imports Xunit
8 |
9 | Namespace Tests.MSCoreReference
10 |
11 | Public NotInheritable Class MsCoreReferenceTest
12 |
13 |
14 | Public Shared Sub VerifyReferencesExist()
15 | Dim tree As SyntaxTree = CSharpSyntaxTree.ParseText("using System; //Not required in VB due to global imports
16 | class test : IComparable { }")
17 |
18 | Dim compilation As CSharpCompilation = CSharpCompilation.Create("MyCompilation", syntaxTrees:={tree}, CSharpReferences("", New List(Of MetadataReference)))
19 | Dim lSemanticModel As SemanticModel = compilation.GetSemanticModel(tree)
20 | Dim inputNode As Syntax.CompilationUnitSyntax = CType(compilation.SyntaxTrees(0).GetRoot, Syntax.CompilationUnitSyntax)
21 | Dim node As Syntax.ClassDeclarationSyntax = CType(inputNode.Members(0), Syntax.ClassDeclarationSyntax)
22 |
23 | Assert.Equal(node.Kind(), SyntaxKind.ClassDeclaration)
24 | Dim classOrInterface As Syntax.TypeSyntax = node.BaseList?.Types.FirstOrDefault()?.Type
25 | Assert.False(classOrInterface Is Nothing)
26 | Dim classSymbolInfo As SymbolInfo = ModelExtensions.GetSymbolInfo(lSemanticModel, classOrInterface)
27 | Assert.NotNull(classSymbolInfo)
28 | Dim classOrInterfaceSymbol As ISymbol = classSymbolInfo.Symbol
29 | Assert.NotNull(classOrInterfaceSymbol)
30 | End Sub
31 |
32 | End Class
33 |
34 | End Namespace
35 |
--------------------------------------------------------------------------------
/CSharpToVB.Tests/Tests/MSCoreReference/ProgressReportTests.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports ProgressReportLibrary
6 | Imports Xunit
7 |
8 | Namespace Tests.MSCoreReference
9 |
10 | Public NotInheritable Class ProgressReportTests
11 |
12 |
13 | Public Shared Sub ProgressReportConstructor()
14 | Dim p As New ProgressReport(1, 10)
15 | Dim p2 As New ProgressReport(1, 10)
16 | Assert.Equal(p.Current, 1)
17 | Assert.Equal(p.Maximum, 10)
18 | Assert.True(p.Equals(p))
19 | Assert.True(p = p2)
20 | Assert.False(p.Equals(New ProgressReport(1, 11)))
21 | Assert.True(p <> New ProgressReport(1, 11))
22 | End Sub
23 |
24 | End Class
25 |
26 | End Namespace
27 |
--------------------------------------------------------------------------------
/CSharpToVB.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.3.32611.2
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "CSharpToVB", "CSharpToVB\CSharpToVB.vbproj", "{5D36ED60-91A7-4D39-BA56-BAFCE97F97C5}"
7 | EndProject
8 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "CodeConverter", "CodeConverter\CodeConverter.vbproj", "{5B4A54BD-E39F-4212-9465-05370D1AD59E}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D43ACB3A-D858-4352-A083-214B9CA331F9}"
11 | ProjectSection(SolutionItems) = preProject
12 | .editorconfig = .editorconfig
13 | License.txt = License.txt
14 | ReadMe.MD = ReadMe.MD
15 | EndProjectSection
16 | EndProject
17 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "CSharpToVB.Tests", "CSharpToVB.Tests\CSharpToVB.Tests.vbproj", "{93A45B05-179A-4EA7-AE67-60B8C71F38A4}"
18 | EndProject
19 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "ProgressReportLibrary", "ProgressReportLibrary\ProgressReportLibrary.vbproj", "{57ABB5E1-80BB-47EE-BCA7-39BA4B9BDDEA}"
20 | EndProject
21 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "csvGenerator", "csvGenerator\csvGenerator.vbproj", "{C7826D19-1C7D-42F3-97CC-4A92C105ACA5}"
22 | EndProject
23 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "TestConsoleApp", "TestConsoleApp\TestConsoleApp.vbproj", "{40E4A63D-16E2-459D-B04E-3BD796173BB6}"
24 | EndProject
25 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ObjectPoolLibrary", "ObjectPoolLibrary\ObjectPoolLibrary.csproj", "{004C2A2F-E9F6-4834-8860-9F425BB5B965}"
26 | EndProject
27 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Releases", "Releases", "{A9BB0885-3845-48D0-B2F7-30C6210894C1}"
28 | EndProject
29 | Global
30 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
31 | Debug|Any CPU = Debug|Any CPU
32 | Release|Any CPU = Release|Any CPU
33 | EndGlobalSection
34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
35 | {5D36ED60-91A7-4D39-BA56-BAFCE97F97C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36 | {5D36ED60-91A7-4D39-BA56-BAFCE97F97C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
37 | {5D36ED60-91A7-4D39-BA56-BAFCE97F97C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
38 | {5D36ED60-91A7-4D39-BA56-BAFCE97F97C5}.Release|Any CPU.Build.0 = Release|Any CPU
39 | {5B4A54BD-E39F-4212-9465-05370D1AD59E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 | {5B4A54BD-E39F-4212-9465-05370D1AD59E}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 | {5B4A54BD-E39F-4212-9465-05370D1AD59E}.Release|Any CPU.ActiveCfg = Release|Any CPU
42 | {5B4A54BD-E39F-4212-9465-05370D1AD59E}.Release|Any CPU.Build.0 = Release|Any CPU
43 | {93A45B05-179A-4EA7-AE67-60B8C71F38A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44 | {93A45B05-179A-4EA7-AE67-60B8C71F38A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
45 | {93A45B05-179A-4EA7-AE67-60B8C71F38A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {93A45B05-179A-4EA7-AE67-60B8C71F38A4}.Release|Any CPU.Build.0 = Release|Any CPU
47 | {57ABB5E1-80BB-47EE-BCA7-39BA4B9BDDEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48 | {57ABB5E1-80BB-47EE-BCA7-39BA4B9BDDEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
49 | {57ABB5E1-80BB-47EE-BCA7-39BA4B9BDDEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
50 | {57ABB5E1-80BB-47EE-BCA7-39BA4B9BDDEA}.Release|Any CPU.Build.0 = Release|Any CPU
51 | {C7826D19-1C7D-42F3-97CC-4A92C105ACA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52 | {C7826D19-1C7D-42F3-97CC-4A92C105ACA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
53 | {C7826D19-1C7D-42F3-97CC-4A92C105ACA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
54 | {C7826D19-1C7D-42F3-97CC-4A92C105ACA5}.Release|Any CPU.Build.0 = Release|Any CPU
55 | {40E4A63D-16E2-459D-B04E-3BD796173BB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56 | {40E4A63D-16E2-459D-B04E-3BD796173BB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
57 | {40E4A63D-16E2-459D-B04E-3BD796173BB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
58 | {40E4A63D-16E2-459D-B04E-3BD796173BB6}.Release|Any CPU.Build.0 = Release|Any CPU
59 | {004C2A2F-E9F6-4834-8860-9F425BB5B965}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60 | {004C2A2F-E9F6-4834-8860-9F425BB5B965}.Debug|Any CPU.Build.0 = Debug|Any CPU
61 | {004C2A2F-E9F6-4834-8860-9F425BB5B965}.Release|Any CPU.ActiveCfg = Release|Any CPU
62 | {004C2A2F-E9F6-4834-8860-9F425BB5B965}.Release|Any CPU.Build.0 = Release|Any CPU
63 | EndGlobalSection
64 | GlobalSection(SolutionProperties) = preSolution
65 | HideSolutionNode = FALSE
66 | EndGlobalSection
67 | GlobalSection(NestedProjects) = preSolution
68 | {A9BB0885-3845-48D0-B2F7-30C6210894C1} = {D43ACB3A-D858-4352-A083-214B9CA331F9}
69 | EndGlobalSection
70 | GlobalSection(ExtensibilityGlobals) = postSolution
71 | SolutionGuid = {766F1CF7-FDEC-4494-A8E2-3E891BCBD997}
72 | EndGlobalSection
73 | EndGlobal
74 |
--------------------------------------------------------------------------------
/CSharpToVB.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | <data><IncludeFilters /><ExcludeFilters /></data>
4 | <data />
--------------------------------------------------------------------------------
/CSharpToVB/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | False
12 |
13 |
14 | False
15 |
16 |
17 | Light Mode
18 |
19 |
20 | 0
21 |
22 |
23 |
24 |
25 |
26 | Consolas, 11.25pt
27 |
28 |
29 | Consolas
30 |
31 |
32 | NETCOREAPP
33 |
34 |
35 | True
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | Text
48 |
49 |
50 | True
51 |
52 |
53 | On
54 |
55 |
56 | True
57 |
58 |
59 | True
60 |
61 |
62 | On
63 |
64 |
65 | True
66 |
67 |
68 | False
69 |
70 |
71 | False
72 |
73 |
74 | False
75 |
76 |
77 | True
78 |
79 |
80 | True
81 |
82 |
83 | True
84 |
85 |
86 | False
87 |
88 |
89 | False
90 |
91 |
92 | True
93 |
94 |
95 | False
96 |
97 |
98 | True
99 |
100 |
101 | Off
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/CSharpToVB/ApplicationEvents.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.VisualBasic.ApplicationServices
6 |
7 | Imports Microsoft.VisualBasic.Devices
8 |
9 | ' ReSharper disable once CheckNamespace
10 | Namespace My
11 |
12 | ' The following events are available for MyApplication:
13 | ' Startup: Raised when the application starts, before the startup form is created.
14 | ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
15 | ' UnhandledException: Raised if the application encounters an unhandled exception.
16 | ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
17 | ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
18 |
19 | Partial Friend Class MyApplication
20 |
21 | Private Sub MyApplication_NetworkAvailabilityChanged(sender As Object, e As NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
22 | ' My.Forms.Form1.SetConnectionStatus(e.IsNetworkAvailable)
23 | End Sub
24 |
25 | Private Sub MyApplication_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
26 | ' My.Application.Log.WriteEntry("Application Shut Down.")
27 | End Sub
28 |
29 | Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
30 | If Me.SplashScreen.InvokeRequired Then
31 | Call Me.SplashScreen.Invoke(New StartupEventHandler(AddressOf Me.MyApplication_Startup), sender, e)
32 | Exit Sub
33 | End If
34 |
35 | ' Get the splash screen.
36 | CType(Me.SplashScreen, SplashScreen1).UserName.Text = $"Current user: " & User.Name
37 | End Sub
38 |
39 | Private Sub MyApplication_StartupNextInstance(sender As Object, e As StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
40 | Stop
41 | End Sub
42 |
43 | Private Sub MyApplication_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
44 | Stop
45 | ' My.Application.Log.WriteException(e.Exception, TraceEventType.Critical, "Unhandled Exception.")
46 | End Sub
47 |
48 | #If NET5_0 And Not NET6_0 Then
49 |
50 | Private Sub MyApplication_ApplyHighDpiMode(sender As Object, e As ApplyHighDpiModeEventArgs) Handles Me.ApplyHighDpiMode
51 | e.HighDpiMode = HighDpiMode.PerMonitorV2
52 | End Sub
53 |
54 | #End If
55 | End Class
56 |
57 | End Namespace
58 |
--------------------------------------------------------------------------------
/CSharpToVB/Assets/DarkModeColorDictionary.csv:
--------------------------------------------------------------------------------
1 | Key,ForegroundR,ForegroundG,ForegroundB,BackgroundR,BackgroundG,BackgroundB
2 | default,255,255,255,30,30,30
3 | class name,0,128,128,18,32,42
4 | comment,0,100,0,18,32,42
5 | constant name,255,255,255,18,32,42
6 | keyword - control,143,8,196,18,32,42
7 | delegate name,0,128,128,18,32,42
8 | enum member name,0,128,128,18,32,42
9 | enum name,0,128,128,18,32,42
10 | error,216,80,80,18,32,42
11 | event name,220,220,220,18,32,42
12 | excluded code,128,128,128,18,32,42
13 | extension method name,220,220,170,18,32,42
14 | field name,220,220,220,18,32,42
15 | Function,141,141,207,18,32,42
16 | identifier,220,220,220,18,32,42
17 | interface name,0,128,128,18,32,42
18 | keyword,86,156,214,18,32,42
19 | label name,220,220,220,18,32,42
20 | local name,254,220,156,18,32,42
21 | method name,220,220,170,18,32,42
22 | module name,78,201,176,18,32,42
23 | namespace name,220,220,220,18,32,42
24 | number,181,206,168,18,32,42
25 | operator,180,180,180,18,32,42
26 | operator - overloaded,220,220,170,18,32,42
27 | parameter name,156,220,254,18,32,42
28 | preprocessor keyword,128,128,128,18,32,42
29 | preprocessor text,220,220,220,18,32,42
30 | property name,156,220,254,18,32,42
31 | punctuation,220,220,220,18,32,42
32 | regex - alternation,0,128,128,18,32,42
33 | regex - anchor,255,192,203,18,32,42
34 | regex - character class,0,0,255,18,32,42
35 | regex - comment,0,100,0,18,32,42
36 | regex - grouping,0,128,128,18,32,42
37 | regex - other escape,165,42,42,18,32,42
38 | regex - quantifier,255,192,203,18,32,42
39 | regex - self escaped character,139,0,0,18,32,42
40 | regex - text,139,0,0,18,32,42
41 | static symbol,95,149,250,18,32,42
42 | string - escape character,255,214,143,18,32,42
43 | string,163,21,21,18,32,42
44 | struct name,43,145,175,18,32,42
45 | text,220,220,220,18,32,42
46 | type parameter name,169,169,169,18,32,42
47 | string - verbatim,128,0,0,18,32,42
48 | xml doc comment - attribute name,128,128,128,18,32,42
49 | xml doc comment - attribute quotes,128,128,128,18,32,42
50 | xml doc comment - attribute value,128,128,128,18,32,42
51 | xml doc comment - cdata section,128,128,128,18,32,42
52 | xml doc comment - comment,128,128,128,18,32,42
53 | xml doc comment - delimiter,128,128,128,18,32,42
54 | xml doc comment - entity reference,0,128,0,18,32,42
55 | xml doc comment - name,128,128,128,18,32,42
56 | xml doc comment - processing instruction,128,128,128,18,32,42
57 | xml doc comment - text,0,128,0,18,32,42
58 | xml literal - attribute name,128,128,128,18,32,42
59 | xml literal - attribute quotes,128,128,128,18,32,42
60 | xml literal - attribute value,128,128,128,18,32,42
61 | xml literal - cdata section,128,128,128,18,32,42
62 | xml literal - comment,128,128,128,18,32,42
63 | xml literal - delimiter,100,100,185,18,32,42
64 | xml literal - embedded expression,128,128,128,18,32,42
65 | xml literal - entity reference,185,100,100,18,32,42
66 | xml literal - name,132,70,70,18,32,42
67 | xml literal - processing instruction,128,128,128,18,32,42
68 | xml literal - text,85,85,85,18,32,42
69 |
--------------------------------------------------------------------------------
/CSharpToVB/Assets/LightModeColorDictionary.csv:
--------------------------------------------------------------------------------
1 | Key,ForegroundR,ForegroundG,ForegroundB,BackgroundR,BackgroundG,BackgroundB
2 | default,0,0,0,255,255,255
3 | class name,0,128,128,255,255,255
4 | comment,0,100,0,255,255,255
5 | constant name,0,0,0,255,255,255
6 | keyword - control,143,8,196,255,255,255
7 | delegate name,0,128,128,255,255,255
8 | enum member name,0,128,128,255,255,255
9 | enum name,0,128,128,255,255,255
10 | error,255,0,0,255,255,255
11 | event name,0,0,0,255,255,255
12 | excluded code,128,128,128,255,255,255
13 | extension method name,0,0,0,255,255,255
14 | field name,0,0,0,255,255,255
15 | Function,0,0,255,255,255,255
16 | identifier,0,0,0,255,255,255
17 | interface name,0,128,128,255,255,255
18 | keyword,0,0,255,255,255,255
19 | label name,0,0,0,255,255,255
20 | local name,0,0,0,255,255,255
21 | method name,0,0,0,255,255,255
22 | module name,0,128,128,255,255,255
23 | namespace name,0,0,0,255,255,255
24 | number,0,0,0,255,255,255
25 | operator,0,0,0,255,255,255
26 | operator - overloaded,0,0,0,255,255,255
27 | parameter name,0,0,0,255,255,255
28 | preprocessor keyword,128,128,128,255,255,255
29 | preprocessor text,0,0,0,255,255,255
30 | property name,0,0,0,255,255,255
31 | punctuation,0,0,0,255,255,255
32 | regex - alternation,0,128,128,255,255,255
33 | regex - anchor,255,192,203,255,255,255
34 | regex - character class,0,0,255,255,255,255
35 | regex - comment,0,100,0,255,255,255
36 | regex - grouping,0,128,128,255,255,255
37 | regex - other escape,165,42,42,255,255,255
38 | regex - quantifier,255,192,203,255,255,255
39 | regex - self escaped character,139,0,0,255,255,255
40 | regex - text,139,0,0,255,255,255
41 | static symbol,0,0,0,255,255,255
42 | string - escape character,0,0,139,255,255,255
43 | string,163,21,21,255,255,255
44 | struct name,43,145,175,255,255,255
45 | text,0,0,0,255,255,255
46 | type parameter name,169,169,169,255,255,255
47 | string - verbatim,128,0,0,255,255,255
48 | xml doc comment - attribute name,128,128,128,255,255,255
49 | xml doc comment - attribute quotes,128,128,128,255,255,255
50 | xml doc comment - attribute value,128,128,128,255,255,255
51 | xml doc comment - cdata section,128,128,128,255,255,255
52 | xml doc comment - comment,128,128,128,255,255,255
53 | xml doc comment - delimiter,128,128,128,255,255,255
54 | xml doc comment - entity reference,0,128,0,255,255,255
55 | xml doc comment - name,128,128,128,255,255,255
56 | xml doc comment - processing instruction,128,128,128,255,255,255
57 | xml doc comment - text,0,128,0,255,255,255
58 | xml literal - attribute name,128,128,128,255,255,255
59 | xml literal - attribute quotes,128,128,128,255,255,255
60 | xml literal - attribute value,128,128,128,255,255,255
61 | xml literal - cdata section,128,128,128,255,255,255
62 | xml literal - comment,128,128,128,255,255,255
63 | xml literal - delimiter,100,100,185,255,255,255
64 | xml literal - embedded expression,128,128,128,255,255,255
65 | xml literal - entity reference,185,100,100,255,255,255
66 | xml literal - name,132,70,70,255,255,255
67 | xml literal - processing instruction,128,128,128,255,255,255
68 | xml literal - text,85,85,85,255,255,255
69 |
--------------------------------------------------------------------------------
/CSharpToVB/CSharpToVB.vbproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
4 | True
5 | True
6 | True
7 | True
8 | True
--------------------------------------------------------------------------------
/CSharpToVB/CSharpToVB.vbproj.vsspell:
--------------------------------------------------------------------------------
1 |
2 |
4 |
--------------------------------------------------------------------------------
/CSharpToVB/ClassificationSupport/ColorDescriptor.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Structure ColorDescriptor
6 | Public Property Foreground As Color
7 | Public Property Background As Color
8 |
9 | Public Sub New(foreground As Color, background As Color)
10 | Me.Foreground = foreground
11 | Me.Background = background
12 | End Sub
13 |
14 | Public Overrides Function Equals(obj As Object) As Boolean
15 | If Not (TypeOf obj Is ColorDescriptor) Then
16 | Return False
17 | End If
18 |
19 | Dim other As ColorDescriptor = DirectCast(obj, ColorDescriptor)
20 | Return Me.Foreground.A = other.Foreground.A AndAlso
21 | Me.Foreground.R = other.Foreground.R AndAlso
22 | Me.Foreground.G = other.Foreground.G AndAlso
23 | Me.Foreground.B = other.Foreground.B AndAlso
24 | Me.Background.A = other.Background.A AndAlso
25 | Me.Background.R = other.Background.R AndAlso
26 | Me.Background.G = other.Background.G AndAlso
27 | Me.Background.B = other.Background.B
28 | End Function
29 |
30 | Public Overrides Function GetHashCode() As Integer
31 | Return HashCode.Combine(Me.Foreground, Me.Background)
32 | End Function
33 |
34 | Public Shared Operator =(left As ColorDescriptor, right As ColorDescriptor) As Boolean
35 | Return left.Equals(right)
36 | End Operator
37 |
38 | Public Shared Operator <>(left As ColorDescriptor, right As ColorDescriptor) As Boolean
39 | Return Not left = right
40 | End Operator
41 |
42 | End Structure
43 |
--------------------------------------------------------------------------------
/CSharpToVB/ColorModeSupport/DarkMode.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.InteropServices
6 |
7 | Public NotInheritable Class DarkMode
8 |
9 | Private Sub New()
10 | End Sub
11 |
12 |
13 | Private Shared Function DwmSetWindowAttribute(hwnd As IntPtr, attr As Integer, ByRef attrValue As Integer, attrSize As Integer) As Integer
14 | End Function
15 |
16 | Public Shared Function IsWindows10(Optional build As Integer = -1) As Boolean
17 | Dim windowsMajor As Integer = Environment.OSVersion.Version.Major
18 | Dim windowsBuild As Integer = Environment.OSVersion.Version.Build
19 | Return windowsMajor >= 10 AndAlso windowsBuild >= build
20 | End Function
21 |
22 | Public Shared Function ToggleImmersiveDarkMode(handle As IntPtr, enabled As Boolean) As Boolean
23 | If RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then
24 | If IsWindows10(17763) Then
25 | Dim attribute As Integer = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1
26 | If IsWindows10(18985) Then
27 | attribute = DWMWA_USE_IMMERSIVE_DARK_MODE
28 | End If
29 | Dim useImmersiveDarkMode As Integer = If(enabled, 1, 0)
30 | Return DwmSetWindowAttribute(handle, attribute, useImmersiveDarkMode, 4) = 0
31 | End If
32 | End If
33 | Return False
34 | End Function
35 |
36 | End Class
37 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/LineNumberItem.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Partial Public Class LineNumbersForRichTextBox
6 |
7 | Private Class LineNumberItem
8 | Friend ReadOnly _lineNumber As Integer
9 | Friend _rectangle As Rectangle
10 |
11 | Friend Sub New(zLineNumber As Integer, zRectangle As Rectangle)
12 | _lineNumber = zLineNumber
13 | _rectangle = zRectangle
14 | End Sub
15 |
16 | End Class
17 |
18 | End Class
19 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/LineNumbersForRichTextBox.Designer.vb:
--------------------------------------------------------------------------------
1 | Imports System.Diagnostics
2 | Imports Microsoft.VisualBasic
3 |
4 |
5 | Partial Class LineNumbersForRichTextBox
6 | Inherits Control
7 |
8 | 'Control overrides dispose to clean up the component list.
9 |
10 | Protected Overrides Sub Dispose(ByVal disposing As Boolean)
11 | Try
12 | If disposing AndAlso components IsNot Nothing Then
13 | components.Dispose()
14 | End If
15 | Finally
16 | MyBase.Dispose(disposing)
17 | End Try
18 | End Sub
19 |
20 | 'Required by the Control Designer
21 | Private components As ComponentModel.IContainer
22 |
23 | ' NOTE: The following procedure is required by the Component Designer
24 | ' It can be modified using the Component Designer. Do not modify it
25 | ' using the code editor.
26 |
27 | Private Sub InitializeComponent()
28 | components = New ComponentModel.Container()
29 | Me.ClientSize = New Size(23, 450)
30 | End Sub
31 |
32 | End Class
33 |
34 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/PanelEx.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.ComponentModel
6 | Imports System.Drawing.Drawing2D
7 |
8 |
9 | Public Class PanelEx
10 | Inherits Panel
11 |
12 | Private _borderStyle As BorderStyle = BorderStyle.FixedSingle
13 | Private _borderColor As Color = SystemColors.WindowFrame
14 | Private _borderWidth As Integer = 1
15 |
16 | Public Sub New()
17 | MyBase.New()
18 | 'SetDefaultControlStyles()
19 | Me.CustomInitialize()
20 | End Sub
21 |
22 | Private Sub CustomInitialize()
23 | Me.SuspendLayout()
24 | Me.BackColor = Color.Transparent
25 | Me.BorderStyle = BorderStyle.FixedSingle
26 | Me.ResumeLayout(False)
27 | End Sub
28 |
29 |
32 | Public Shadows Property BorderStyle() As BorderStyle
33 | Get
34 | Return _borderStyle
35 | End Get
36 | Set
37 | _borderStyle = Value
38 | If Me.DesignMode Then Me.Invalidate()
39 | End Set
40 | End Property
41 |
42 |
45 | Public Property BorderColor() As Color
46 | Get
47 | Return _borderColor
48 | End Get
49 | Set
50 | _borderColor = Value
51 | 'If DesignMode Then
52 | Me.Invalidate()
53 | 'End If
54 | End Set
55 | End Property
56 |
57 |
60 | Public Property BorderWidth() As Integer
61 | Get
62 | Return _borderWidth
63 | End Get
64 | Set
65 | _borderWidth = Value
66 | If Me.DesignMode Then Me.Invalidate()
67 | End Set
68 | End Property
69 |
70 | Protected Overrides Sub OnPaintBackGround(e As PaintEventArgs)
71 |
72 | MyBase.OnPaintBackground(e)
73 |
74 | e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
75 |
76 | Select Case _borderStyle
77 | Case BorderStyle.FixedSingle
78 | Using borderPen As New Pen(_borderColor, _borderWidth)
79 | If _borderWidth > 1 Then
80 | Dim path As New GraphicsPath
81 | Try
82 | Dim offset As Integer = If(_borderStyle = BorderStyle.FixedSingle AndAlso
83 | _borderWidth > 1, Me.BorderWidth \ 2, 0)
84 | path.AddRectangle(Rectangle.Inflate(Me.ClientRectangle, -offset, -offset))
85 | e.Graphics.DrawPath(borderPen, path)
86 | Finally
87 | path.Dispose()
88 | End Try
89 | Else
90 | 'path.AddRectangle(ClientRectangle)
91 | Dim rect As Rectangle = Me.ClientRectangle
92 | rect.Width -= 1 : rect.Height -= 1
93 | e.Graphics.DrawRectangle(borderPen, rect)
94 | End If
95 | End Using
96 |
97 | Case BorderStyle.Fixed3D
98 | e.Graphics.SmoothingMode = SmoothingMode.Default
99 | e.Graphics.DrawLine(SystemPens.ControlDark, Me.ClientRectangle.X, Me.ClientRectangle.Y, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Y)
100 | e.Graphics.DrawLine(SystemPens.ControlDark, Me.ClientRectangle.X, Me.ClientRectangle.Y, Me.ClientRectangle.X, Me.ClientRectangle.Height - 1)
101 | e.Graphics.DrawLine(SystemPens.ControlDarkDark, Me.ClientRectangle.X + 1, Me.ClientRectangle.Y + 1, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Y + 1)
102 | e.Graphics.DrawLine(SystemPens.ControlDarkDark, Me.ClientRectangle.X + 1, Me.ClientRectangle.Y + 1, Me.ClientRectangle.X + 1, Me.ClientRectangle.Height - 1)
103 | e.Graphics.DrawLine(SystemPens.ControlLight, Me.ClientRectangle.X + 1, Me.ClientRectangle.Height - 2, Me.ClientRectangle.Width - 2, Me.ClientRectangle.Height - 2)
104 | e.Graphics.DrawLine(SystemPens.ControlLight, Me.ClientRectangle.Width - 2, Me.ClientRectangle.Y + 1, Me.ClientRectangle.Width - 2, Me.ClientRectangle.Height - 2)
105 | e.Graphics.DrawLine(SystemPens.ControlLightLight, Me.ClientRectangle.X, Me.ClientRectangle.Height - 1, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Height - 1)
106 | e.Graphics.DrawLine(SystemPens.ControlLightLight, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Y, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Height - 1)
107 |
108 | Case BorderStyle.None
109 |
110 | End Select
111 |
112 | End Sub
113 |
114 | End Class
115 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/ToolStripCheckBox.Designer.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Diagnostics
6 |
7 | Partial Public Class ToolStripCheckBox
8 | Inherits ToolStripControlHost
9 |
10 | 'Required by the Control Designer
11 | Private components As ComponentModel.IContainer
12 |
13 | ' NOTE: The following procedure is required by the Component Designer
14 | ' It can be modified using the Component Designer. Do not modify it
15 | ' using the code editor.
16 |
17 | Private Sub InitializeComponent()
18 | components = New ComponentModel.Container()
19 | End Sub
20 |
21 | 'Control overrides dispose to clean up the component list.
22 |
23 | Protected Overrides Sub Dispose(ByVal disposing As Boolean)
24 | Try
25 | If disposing AndAlso components IsNot Nothing Then
26 | components.Dispose()
27 | End If
28 | Finally
29 | MyBase.Dispose(disposing)
30 | End Try
31 | End Sub
32 | End Class
33 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/ToolStripCheckBox.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class ToolStripCheckBox
6 |
7 | Public Sub New()
8 | MyBase.New(New CheckBox)
9 | End Sub
10 |
11 | 'Declare the event
12 | Public Event CheckedChanged As EventHandler
13 |
14 | 'Expose the CheckBoxControl's Checked Property
15 | Public Property Checked() As Boolean
16 | Get
17 | Return CType(Me.Control, CheckBox).Checked
18 | End Get
19 | Set
20 | CType(Me.Control, CheckBox).Checked = Value
21 | End Set
22 | End Property
23 |
24 | 'Raise the event
25 | Private Sub CheckedChangedHandler(sender As Object, e As EventArgs)
26 | RaiseEvent CheckedChanged(Me, e)
27 | End Sub
28 |
29 | 'Subscribe and Unsubscribe the events you wish to expose
30 | Protected Overrides Sub OnSubscribeControlEvents(ctrl As Control)
31 | If ctrl Is Nothing Then
32 | Throw New ArgumentNullException(NameOf(ctrl))
33 | End If
34 | 'Connect the base events
35 | MyBase.OnSubscribeControlEvents(ctrl)
36 |
37 | 'Add any events you want to expose
38 | AddHandler CType(ctrl, CheckBox).CheckedChanged, AddressOf Me.CheckedChangedHandler
39 | End Sub
40 |
41 | Protected Overrides Sub OnUnsubscribeControlEvents(ctrl As Control)
42 | If ctrl Is Nothing Then
43 | Throw New ArgumentNullException(NameOf(ctrl))
44 | End If
45 | 'Disconnect the base events
46 | MyBase.OnUnsubscribeControlEvents(ctrl)
47 |
48 | 'Remove any events you have exposed
49 | RemoveHandler CType(ctrl, CheckBox).CheckedChanged, AddressOf Me.CheckedChangedHandler
50 | End Sub
51 |
52 | End Class
53 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/ToolStripComboBoxEx.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class ToolStripComboBoxEx
6 | Inherits ToolStripControlHost
7 |
8 | Public Sub New()
9 | MyBase.New(New ComboBoxEx With {.BorderDrawMode = ComboBoxEx.ControlBorderDrawMode.InternalFaded, .FlatStyle = FlatStyle.Flat})
10 | End Sub
11 |
12 | End Class
13 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/ToolStripTextProgressBar.Designer.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Diagnostics
6 |
7 | Partial Public Class ToolStripTextProgressBar
8 | 'Required by the Control Designer
9 | Private components As ComponentModel.IContainer
10 |
11 | ' NOTE: The following procedure is required by the Component Designer
12 | ' It can be modified using the Component Designer. Do not modify it
13 | ' using the code editor.
14 |
15 | Private Sub InitializeComponent()
16 | components = New ComponentModel.Container()
17 | End Sub
18 |
19 | 'Control overrides dispose to clean up the component list.
20 |
21 | Protected Overrides Sub Dispose(ByVal disposing As Boolean)
22 | Try
23 | If disposing AndAlso components IsNot Nothing Then
24 | components.Dispose()
25 | End If
26 | Finally
27 | MyBase.Dispose(disposing)
28 | End Try
29 | End Sub
30 | End Class
31 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/ToolStripTextProgressBar.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Drawing.Drawing2D
6 | Imports System.Threading
7 | Imports ProgressReportLibrary
8 |
9 | Public Class ToolStripTextProgressBar
10 | Inherits ToolStripProgressBar
11 |
12 | Public Sub New()
13 | Me.TextImageRelation = TextImageRelation.Overlay
14 | Me.Value = 0
15 | End Sub
16 |
17 | Public Property DisplayIncrement As Integer = 10
18 |
19 | Public Overloads Property Maximum() As Integer
20 | Get
21 | Return MyBase.Maximum
22 | End Get
23 | Set
24 | MyBase.Maximum = Value
25 |
26 | End Set
27 | End Property
28 |
29 | Private Sub PbPrecentage(txt As String)
30 | Me.Invalidate()
31 | Using g As Graphics = Me.ProgressBar.CreateGraphics()
32 | g.PixelOffsetMode = PixelOffsetMode.HighSpeed
33 | 'Switch to Anti-aliased drawing for better (smoother) graphic results
34 | g.SmoothingMode = SmoothingMode.AntiAlias
35 | TextRenderer.MeasureText(g, txt, Me.Font)
36 | Dim sizeF As SizeF = g.MeasureString(txt, Me.Font)
37 | Dim pt As New Point(CInt((Me.Width / 2) - (sizeF.Width / 2.0F)), CInt((Me.Height / 2) - (sizeF.Height / 2.0F)))
38 | TextRenderer.DrawText(g, txt, Me.Font, pt, Color.Black)
39 | End Using
40 | End Sub
41 |
42 | Public Sub Clear()
43 | Me.Value = 0
44 | End Sub
45 |
46 | '''
47 | ''' Advances the current position of the underlying Progress Bar by the specified amount.
48 | '''
49 | ''' The amount by which to increment the underlying progress bar's current position.
50 | Public Overloads Sub Increment(val As Integer)
51 | MyBase.Increment(val)
52 | If Me.Value >= Me.Maximum Then
53 | Me.Value = 0
54 | Exit Sub
55 | End If
56 | If Me.Value Mod Me.DisplayIncrement = 0 Then
57 | Me.PbPrecentage($"{ Me.Value:N0} of { Me.Maximum:N0}")
58 | Thread.Sleep(1)
59 | End If
60 | End Sub
61 |
62 | Public Sub Update(val As ProgressReport)
63 | If Me.Maximum <> val.Maximum Then
64 | Me.Maximum = val.Maximum
65 | End If
66 | Me.Value = val.Current
67 | If val.Current = 0 Then
68 | Exit Sub
69 | End If
70 | If val.Current >= Me.Maximum Then
71 | Me.Clear()
72 | Exit Sub
73 | End If
74 |
75 | If Me.Value Mod Me.DisplayIncrement = 0 Then
76 | Me.PbPrecentage($"{val.Current:N0} of {val.Maximum:N0}")
77 | If Debugger.IsAttached Then
78 | Thread.Sleep(1)
79 | End If
80 | End If
81 | End Sub
82 |
83 | End Class
84 |
--------------------------------------------------------------------------------
/CSharpToVB/Controls/WindowsMessageIDs.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Module WindowsMessageIDs
6 |
7 | ' ReSharper disable InconsistentNaming
8 | Friend Const DWMWA_USE_IMMERSIVE_DARK_MODE As Integer = 20
9 |
10 | Friend Const DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 As Integer = 19
11 | Friend Const WM_NCPAINT As Integer = &H85
12 | Friend Const WM_PAINT As Integer = &HF
13 | Friend Const WM_SYNCPAINT As Integer = &H88
14 | ' ReSharper restore InconsistentNaming
15 | End Module
16 |
--------------------------------------------------------------------------------
/CSharpToVB/Extensions/MenuExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 | Imports System.Runtime.CompilerServices
7 |
8 | Friend Module MenuExtensions
9 |
10 | Private Sub FileMenuMRUList_MouseDown(sender As Object, e As MouseEventArgs)
11 | If e.Button = MouseButtons.Right Then
12 | Clipboard.SetText(text:=CType(sender, ToolStripMenuItem).Text)
13 | End If
14 | End Sub
15 |
16 |
17 | Friend Sub FileMenuMruUpdateUi(dropDownItems As ToolStripItemCollection, clickEvent As EventHandler)
18 | ' clear MRU menu items...
19 | Dim mruToolStripItems As New List(Of ToolStripItem)
20 | ' create a temporary collection containing every MRU menu item
21 | ' (identified by the tag text when added to the list)...
22 | For Each fileMenuItem As ToolStripItem In dropDownItems
23 | If fileMenuItem.Tag IsNot Nothing Then
24 | If fileMenuItem.Tag.ToString().StartsWith("MRU:", StringComparison.Ordinal) Then
25 | mruToolStripItems.Add(fileMenuItem)
26 | End If
27 | End If
28 | Next
29 | ' iterate through list and remove each from menu...
30 | For Each mruToolStripItem As ToolStripItem In mruToolStripItems
31 | RemoveHandler mruToolStripItem.Click, clickEvent
32 | RemoveHandler mruToolStripItem.MouseDown, AddressOf FileMenuMRUList_MouseDown
33 | dropDownItems.Remove(mruToolStripItem)
34 | mruToolStripItem.Dispose()
35 | Next
36 | ' display items (in reverse order so the most recent is on top)...
37 | For iCounter As Integer = My.Settings.MRU_Data.Count - 1 To 0 Step -1
38 | Dim sPath As String = My.Settings.MRU_Data(iCounter)
39 | ' create new ToolStripItem, displaying the name of the file...
40 | ' set the tag - identifies the ToolStripItem as an MRU item and
41 | ' contains the full path so it can be opened later...
42 | Dim clsItem As New ToolStripMenuItem(sPath) With {
43 | .Tag = "MRU:" & sPath
44 | }
45 | ' hook into the click event handler so we can open the file later...
46 | AddHandler clsItem.Click, clickEvent
47 | AddHandler clsItem.MouseDown, AddressOf FileMenuMRUList_MouseDown
48 | ' insert into DropDownItems list...
49 | dropDownItems.Insert(dropDownItems.Count - 10, clsItem)
50 | Next
51 |
52 | End Sub
53 |
54 |
55 | Friend Function IndexOf(contextMenu As ContextMenuStrip, text As String, Optional searchAllChildren As Boolean = False) As Integer
56 | Return contextMenu.Items.IndexOf(contextMenu.Items.Find(text, searchAllChildren)(0))
57 | End Function
58 |
59 |
60 | Friend Sub MenuAddToMru(mruData As Specialized.StringCollection, text As String)
61 | ' remove the item from the collection if exists so that we can
62 | ' re-add it to the beginning...
63 | If mruData.Contains(text) Then
64 | mruData.Remove(text)
65 | End If
66 | ' add to MRU list..
67 | mruData.Add(text)
68 | ' make sure there are only ever 5 items...
69 | While mruData.Count > 5
70 | mruData.RemoveAt(0)
71 | End While
72 | End Sub
73 |
74 |
75 | Friend Sub TsFindWhatMruUpdateUi(dropDownItems As ToolStripComboBox)
76 | If My.Settings.TSFindWhatMRU_Data Is Nothing Then
77 | My.Settings.TSFindWhatMRU_Data = New Specialized.StringCollection
78 | My.Settings.Save()
79 | End If
80 | ' clear MRU menu items...
81 | dropDownItems.Items.Clear()
82 | ' display items (in reverse order so the most recent is on top)...
83 | For iCounter As Integer = My.Settings.TSFindWhatMRU_Data.Count - 1 To 0 Step -1
84 | dropDownItems.Items.Add(My.Settings.TSFindWhatMRU_Data(iCounter))
85 | Next
86 | End Sub
87 |
88 |
89 | Friend Sub UpdateLastFileMenu(mainForm As Form1)
90 | ' load MRU...
91 | If My.Settings.MRU_Data Is Nothing Then
92 | My.Settings.MRU_Data = New Specialized.StringCollection
93 | End If
94 |
95 | My.Settings.Save()
96 |
97 | ' show separator...
98 | If My.Settings.MRU_Data.Count > 0 Then
99 | mainForm.MenuFileLastFolder.Text = Path.GetDirectoryName(My.Settings.MRU_Data.Last)
100 | mainForm.MenuFileLastFolder.Visible = True
101 | mainForm.MenuFileSep1.Visible = True
102 | mainForm.MenuFileSep2.Visible = True
103 | Else
104 | mainForm.MenuFileLastFolder.Visible = False
105 | mainForm.MenuFileSep1.Visible = False
106 | mainForm.MenuFileSep2.Visible = False
107 | End If
108 | End Sub
109 |
110 | End Module
111 |
--------------------------------------------------------------------------------
/CSharpToVB/Extensions/RichTextBoxExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 |
7 | Friend Module RichTextBoxExtensions
8 |
9 |
10 | Public Function FindIndexOfAny(rtb As RichTextBox, ParamArray strings() As String) As Integer
11 | For Each s As String In strings
12 | Dim keywordIndex As Integer = rtb.Find(s)
13 | If keywordIndex >= 0 Then
14 | Return keywordIndex
15 | End If
16 | Next
17 | Return -1
18 | End Function
19 |
20 | End Module
21 |
--------------------------------------------------------------------------------
/CSharpToVB/Extensions/SpecializedCollection.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 |
7 | Partial Public Module SpecializedCollection
8 |
9 |
10 | Public Function Last(stringCollection As Specialized.StringCollection) As String
11 |
12 | Return If(stringCollection Is Nothing OrElse stringCollection.Count = 0, "", stringCollection.Item(stringCollection.Count - 1))
13 | End Function
14 |
15 | End Module
16 |
--------------------------------------------------------------------------------
/CSharpToVB/Extensions/StringExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 |
7 | Public Module StringExtensions
8 |
9 |
10 | Public Function Count(value As String, ch As Char) As Integer
11 | If value Is Nothing Then
12 | Return 0
13 | End If
14 | Return value.Count(Function(c As Char) c = ch)
15 | End Function
16 |
17 |
18 | Public Function Join(source As IEnumerable(Of String), separator As String) As String
19 | If source Is Nothing Then
20 | Throw New ArgumentNullException(NameOf(source))
21 | End If
22 |
23 | If separator Is Nothing Then
24 | Throw New ArgumentNullException(NameOf(separator))
25 | End If
26 |
27 | Return String.Join(separator, source)
28 | End Function
29 |
30 | End Module
31 |
--------------------------------------------------------------------------------
/CSharpToVB/Forms/AboutBox1.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.VisualBasic.ApplicationServices
6 |
7 | Public NotInheritable Class AboutBox1
8 | Private ReadOnly _enableDarkMode As Boolean = False
9 |
10 | Public Sub New(lightMode As Boolean)
11 | Me.InitializeComponent()
12 | _enableDarkMode = Not lightMode
13 | End Sub
14 |
15 | Private Sub AboutBox1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
16 | DarkMode.ToggleImmersiveDarkMode(Me.Handle, _enableDarkMode)
17 | ' Set the title of the form.
18 | Dim applicationTitle As String = If(My.Application.Info.Title, IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName))
19 | Me.Text = $"About {applicationTitle}"
20 | ' Initialize all of the text displayed on the About Box.
21 |
22 | Me.LabelProductName.Text = $"{My.Application.Info.ProductName}"
23 | Me.LabelVersion.Text = $"Version {My.Application.Info.Version}"
24 |
25 | Me.LabelCopyright.Text = My.Application.Info.Copyright
26 | Me.LabelCompanyName.Text = $"Developer {My.Application.Info.CompanyName}"
27 | Dim codeConverterInfo As New AssemblyInfo(GetType(CodeWithOptions).Assembly)
28 | Dim objectPoolLibrary As New AssemblyInfo(GetType(ObjectPoolLibrary.ObjectPool(Of String)).Assembly)
29 | Dim progressReportLibrary As New AssemblyInfo(GetType(ProgressReportLibrary.ProgressReport).Assembly)
30 | Me.TextBoxDescription.Text = $"{My.Application.Info.Description}
31 |
32 | {codeConverterInfo.ProductName} {codeConverterInfo.Version}
33 | {objectPoolLibrary.ProductName} {objectPoolLibrary.Version}
34 | {progressReportLibrary.ProductName} {progressReportLibrary.Version}"
35 | End Sub
36 |
37 | Private Sub OKButton_Click(sender As Object, e As EventArgs) Handles OKButton.Click
38 | Me.Close()
39 | End Sub
40 |
41 | End Class
42 |
--------------------------------------------------------------------------------
/CSharpToVB/Forms/IgnoreFilesWithErrorsListDialog.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
61 | True
62 |
63 |
64 |
--------------------------------------------------------------------------------
/CSharpToVB/Forms/IgnoreFilesWithErrorsListDialog.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | ' ReSharper disable once UnusedMemberInSuper.Global
6 |
7 | Public Class IgnoreFilesWithErrorsListDialog
8 | Private ReadOnly _listString As New List(Of String)()
9 | Private _fileToLoad As String = ""
10 |
11 | Public ReadOnly Property FileToLoad As String
12 | Get
13 | Return _fileToLoad
14 | End Get
15 | End Property
16 |
17 | Private Sub btlClearErrorFileList_Click_1(sender As Object, e As EventArgs) Handles btlClearErrorFileList.Click
18 | My.Settings.IgnoreFileList.Clear()
19 | Me.UpdateGrid()
20 | End Sub
21 |
22 | Private Sub Cancel_Button_Click(sender As Object, e As EventArgs) Handles Cancel_Button.Click
23 | Me.DialogResult = DialogResult.Cancel
24 | Me.Close()
25 | End Sub
26 |
27 | Private Sub dgvIgnoredFilesList_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIgnoredFilesList.CellClick
28 | ' Ignore clicks that are not on button cells.
29 | If e.RowIndex < 0 Then
30 | Exit Sub
31 | End If
32 | Select Case e.ColumnIndex
33 | Case Me.dgvIgnoredFilesList.Columns("Delete").Index
34 | My.Settings.IgnoreFileList.RemoveAt(e.RowIndex)
35 | Me.UpdateGrid()
36 | Case Me.dgvIgnoredFilesList.Columns("Load").Index
37 | _fileToLoad = My.Settings.IgnoreFileList(e.RowIndex)
38 | Me.OK_Button.PerformClick()
39 | Case Else
40 | Exit Sub
41 | End Select
42 | End Sub
43 |
44 | Private Sub IgnoreFilesWithErrorsListDialog_Load(sender As Object, e As EventArgs) Handles Me.Load
45 | DarkMode.ToggleImmersiveDarkMode(CType(Me.Controls(0).Parent, Form).Handle, True)
46 | Me.UpdateGrid()
47 | If Me.dgvIgnoredFilesList.Columns.Count > 1 Then
48 | Exit Sub
49 | End If
50 | ' Initialize the button column.
51 | _fileToLoad = ""
52 | End Sub
53 |
54 | Private Sub OK_Button_Click(sender As Object, e As EventArgs) Handles OK_Button.Click
55 | Me.DialogResult = DialogResult.OK
56 | My.Settings.Save()
57 | Me.Close()
58 | End Sub
59 |
60 | Private Sub UpdateGrid()
61 | _listString.Clear()
62 | For Each s As String In My.Settings.IgnoreFileList
63 | _listString.Add(s)
64 | Next
65 | Me.dgvIgnoredFilesList.DataSource = _listString.Select(Function(x As String) New With {Key .Value = x}).ToList()
66 | End Sub
67 |
68 | End Class
69 |
--------------------------------------------------------------------------------
/CSharpToVB/Forms/OptionsDialog.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
61 |
--------------------------------------------------------------------------------
/CSharpToVB/Forms/SplashScreen1.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Globalization
6 |
7 | Public NotInheritable Class SplashScreen1
8 |
9 | Private Sub SplashScreen1_Load(sender As Object, e As EventArgs) Handles Me.Load
10 | 'Set up the dialog text at runtime according to the application's assembly information.
11 |
12 | Me.ApplicationTitle.Text = If(String.IsNullOrWhiteSpace(My.Application.Info.Title), IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName), My.Application.Info.Title)
13 |
14 | 'Format the version information using the text set into the Version control at design time as the
15 | ' formatting string. This allows for effective localization if desired.
16 | ' Build and revision information could be included by using the following code and changing the
17 | ' Version control's design-time text to "Version {0}.{1:00}.{2}.{3}" or something similar. See
18 | ' String.Format() in Help for more information.
19 | '
20 | Me.Version.Text = String.Format(CultureInfo.InvariantCulture, Me.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision)
21 |
22 | 'Copyright info
23 | Me.Copyright.Text = My.Application.Info.Copyright
24 | End Sub
25 |
26 | End Class
27 |
--------------------------------------------------------------------------------
/CSharpToVB/Icons/CStoVB.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Icons/CStoVB.ico
--------------------------------------------------------------------------------
/CSharpToVB/Icons/NotificationAlert_16x.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Icons/NotificationAlert_16x.ico
--------------------------------------------------------------------------------
/CSharpToVB/Images/AboutBox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/AboutBox.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/AboutBoxDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/AboutBoxDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/AdvancedView.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/AdvancedView.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/AdvancedViewDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/AdvancedViewDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Copy.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/CopyDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/CopyDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Cut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Cut.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/CutDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/CutDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Exit.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/ExitDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/ExitDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/FeedbackSmile_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/FeedbackSmile_16x.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/FeedbackSmile_16xDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/FeedbackSmile_16xDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/FindNext.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/FindNext.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/FindNextDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/FindNextDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/NotificationAlertGray_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/NotificationAlertGray_16x.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/NotificationAlertRed_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/NotificationAlertRed_16x.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/NotificationAlert_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/NotificationAlert_16x.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/OpenFile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/OpenFile.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/OpenFileDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/OpenFileDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/OpenProjectFolder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/OpenProjectFolder.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/OpenProjectFolderDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/OpenProjectFolderDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Paste.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/PasteDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/PasteDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Redo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Redo.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/RedoDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/RedoDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/ScreenShot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/ScreenShot.jpg
--------------------------------------------------------------------------------
/CSharpToVB/Images/SelectAll.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/SelectAll.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/SelectAllDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/SelectAllDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Snippet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Snippet.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/SnippetDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/SnippetDark.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/Undo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/Undo.png
--------------------------------------------------------------------------------
/CSharpToVB/Images/UndoDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/CSharpToVB/Images/UndoDark.png
--------------------------------------------------------------------------------
/CSharpToVB/My Project/Application.Designer.HighDpi.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | 'This constant indicates whether the Application Framework is in use.
6 | #Const APPLICATION_FRAMEWORK = True
7 |
8 | #If APPLICATION_FRAMEWORK Then
9 |
10 | #If NET5_0 And Not NET6_0 Then
11 |
12 | Imports System.Collections.ObjectModel
13 |
14 | Namespace My
15 |
16 | Partial Friend Class MyApplication
17 |
18 | Public Event ApplyHighDpiMode(sender As Object, e As ApplyHighDpiModeEventArgs)
19 |
20 | Private _highDpiMode As HighDpiMode?
21 |
22 | Friend Shadows Property HighDpiMode As HighDpiMode
23 | Get
24 | Return If(
25 | _highDpiMode Is Nothing,
26 | Application.HighDpiMode,
27 | _highDpiMode.Value)
28 | End Get
29 | Set(value As HighDpiMode)
30 | _highDpiMode = value
31 | End Set
32 | End Property
33 |
34 | ' IMPORTANT:
35 | ' If this method causes an compilation error after you've unchecked 'Application Framework'
36 | ' in the project properties, go to the top of this file and change the value to 'False' in this line:
37 | ' #Const APPLICATION_FRAMEWORK = False
38 |
39 | ' For more about using WinForms without the Application Framework
40 | ' see: https://aka.ms/visualbasic-appframework-net5
41 | Protected Overrides Function OnInitialize(commandLineArgs As ReadOnlyCollection(Of String)) As Boolean
42 | Dim eventArgs As New ApplyHighDpiModeEventArgs(
43 | If(
44 | _highDpiMode Is Nothing,
45 | HighDpiMode.SystemAware,
46 | _highDpiMode.Value))
47 |
48 | RaiseEvent ApplyHighDpiMode(Me, eventArgs)
49 |
50 | System.Windows.Forms.Application.SetHighDpiMode(eventArgs.HighDpiMode)
51 |
52 | Return MyBase.OnInitialize(commandLineArgs)
53 | End Function
54 |
55 | End Class
56 |
57 | Public Class ApplyHighDpiModeEventArgs
58 | Inherits EventArgs
59 |
60 | Public Sub New(highDpiMode As HighDpiMode)
61 | Me.HighDpiMode = highDpiMode
62 | End Sub
63 |
64 | Public Property HighDpiMode As HighDpiMode
65 |
66 | End Class
67 |
68 | End Namespace
69 |
70 | #End If ' #If NET5_0 And Not NET6_0
71 | #End If ' #If APPLICATION_FRAMEWORK
72 |
--------------------------------------------------------------------------------
/CSharpToVB/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | 'NOTE: This file is auto-generated; do not modify it directly. To make changes,
18 | ' or if you encounter build errors in this file, go to the Project Designer
19 | ' (go to Project Properties or double-click the My Project node in
20 | ' Solution Explorer), and make changes on the Application tab.
21 | '
22 | Partial Friend Class MyApplication
23 |
24 | _
25 | Public Sub New()
26 | MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
27 | Me.IsSingleInstance = true
28 | Me.EnableVisualStyles = true
29 | Me.SaveMySettingsOnExit = true
30 | Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
31 | End Sub
32 |
33 | _
34 | Protected Overrides Sub OnCreateMainForm()
35 | Me.MainForm = Global.CSharpToVBApp.Form1
36 | End Sub
37 |
38 | _
39 | Protected Overrides Sub OnCreateSplashScreen()
40 | Me.SplashScreen = Global.CSharpToVBApp.SplashScreen1
41 | End Sub
42 | End Class
43 | End Namespace
44 |
--------------------------------------------------------------------------------
/CSharpToVB/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | Form1
5 | true
6 | 0
7 | true
8 | 0
9 | SplashScreen1
10 | true
11 |
--------------------------------------------------------------------------------
/CSharpToVB/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | False
7 |
8 |
9 | False
10 |
11 |
12 | Light Mode
13 |
14 |
15 | 0
16 |
17 |
18 |
19 |
20 |
21 | Consolas, 11.25pt
22 |
23 |
24 | Consolas
25 |
26 |
27 | NETCOREAPP
28 |
29 |
30 |
31 |
32 |
33 | True
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Text
49 |
50 |
51 | True
52 |
53 |
54 | On
55 |
56 |
57 | True
58 |
59 |
60 | True
61 |
62 |
63 | On
64 |
65 |
66 | True
67 |
68 |
69 | False
70 |
71 |
72 | False
73 |
74 |
75 | False
76 |
77 |
78 | True
79 |
80 |
81 | True
82 |
83 |
84 | True
85 |
86 |
87 | False
88 |
89 |
90 | False
91 |
92 |
93 | True
94 |
95 |
96 |
97 |
98 |
99 | False
100 |
101 |
102 | True
103 |
104 |
105 | Off
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/CSharpToVB/My Project/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/CSharpToVB/SupportClasses/MyListItem.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class MyListItem
6 |
7 | Public Sub New(pText As String, pValue As String)
8 | Me.Text = pText
9 | Me.Value = pValue
10 | End Sub
11 |
12 | Public ReadOnly Property Text As String
13 |
14 | Public ReadOnly Property Value As String
15 |
16 | Public Overrides Function ToString() As String
17 | Return Me.Text
18 | End Function
19 |
20 | End Class
21 |
--------------------------------------------------------------------------------
/CSharpToVB/SupportClasses/NumberedListItem.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class NumberedListItem
6 |
7 | Public Sub New(display As String, value As String)
8 | Me.DisplayItem = display
9 | Me.ValueItem = value
10 | End Sub
11 |
12 | Private Property DisplayItem As String
13 | Public Property ValueItem As String
14 |
15 | Public Function SourceFileWithPath() As String
16 | If String.IsNullOrEmpty(Me.DisplayItem) Then
17 | Return String.Empty
18 | End If
19 | Return Me.DisplayItem.Split(" ", StringSplitOptions.RemoveEmptyEntries)(1)
20 | End Function
21 |
22 | Public Overrides Function ToString() As String
23 | Return Me.DisplayItem.ToString(Globalization.CultureInfo.CurrentCulture)
24 | End Function
25 |
26 | End Class
27 |
--------------------------------------------------------------------------------
/CSharpToVB/SupportClasses/ProcessingStats.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public NotInheritable Class ProcessingStats
6 |
7 | Public Sub New(lastFileNameWithPath As String)
8 | Me.LastFileNameWithPath = lastFileNameWithPath
9 | _elapsedTimer = New Diagnostics.Stopwatch
10 | _elapsedTimer.Start()
11 | End Sub
12 |
13 | Public ReadOnly _elapsedTimer As Diagnostics.Stopwatch
14 | Public Property FilesProcessed As Long
15 | Public Property LastFileNameWithPath As String
16 | Public Property TotalFilesToProcess As Long
17 | End Class
18 |
--------------------------------------------------------------------------------
/CSharpToVB/SupportClasses/Range.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis.Classification
6 | Imports Microsoft.CodeAnalysis.Text
7 |
8 | Public Class Range
9 |
10 | Friend Sub New(classification As String, span As TextSpan, text As SourceText)
11 | Me.New(classification, span, text.GetSubText(span).ToString())
12 | End Sub
13 |
14 | Public Sub New(classification As String, span As TextSpan, text As String)
15 | Me.New(New ClassifiedSpan(classification, span), text)
16 | End Sub
17 |
18 | Public Sub New(classifiedSpan As ClassifiedSpan, text As String)
19 | Me.ClassifiedSpan = classifiedSpan
20 | Me.Text = text
21 | End Sub
22 |
23 | Public ReadOnly Property ClassificationType As String
24 | Get
25 | Return Me.ClassifiedSpan.ClassificationType
26 | End Get
27 | End Property
28 |
29 | Public ReadOnly Property ClassifiedSpan As ClassifiedSpan
30 |
31 | Public ReadOnly Property Text As String
32 |
33 | Public ReadOnly Property TextSpan As TextSpan
34 | Get
35 | Return Me.ClassifiedSpan.TextSpan
36 | End Get
37 | End Property
38 |
39 | End Class
40 |
--------------------------------------------------------------------------------
/CSharpToVB/Utilities/LoadBufferSupport.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 | Imports Microsoft.CodeAnalysis
7 |
8 | Friend Module LoadBufferSupport
9 |
10 | Public Function LoadInputBufferFromStream(mainForm As Form1, path As String) As Integer
11 | If Not File.Exists(path) Then
12 | Return 0
13 | End If
14 | mainForm.ConversionInput.Visible = False
15 | Dim sourceText As String
16 | mainForm.LineNumbersForConversionInput.Visible = False
17 | Using myFileStream As FileStream = File.OpenRead(path)
18 | sourceText = myFileStream.GetFileTextFromStream()
19 | End Using
20 |
21 | Dim lines() As String = sourceText.SplitLines
22 | If mainForm.MenuOptionsColorizeSource.Checked Then
23 | Colorize(mainForm, GetClassifiedRanges(lines.Join(vbCrLf), LanguageNames.CSharp).ToList(), mainForm.ConversionInput, lines.Length)
24 | mainForm.ConversionInput.Select(0, 0)
25 | Else
26 | mainForm.ConversionInput.Text = lines.Join(vbCrLf)
27 | End If
28 | mainForm.ConversionInput.Visible = True
29 | mainForm.LineNumbersForConversionInput.Visible = mainForm.MenuViewShowSourceLineNumbers.Checked
30 | Application.DoEvents()
31 | Return lines.Length
32 | End Function
33 |
34 | Friend Sub LoadOutputBufferFromStream(mainForm As Form1, path As String)
35 | Dim sourceText As String
36 | mainForm.LineNumbersForConversionOutput.Visible = False
37 | Using myFileStream As FileStream = File.OpenRead(path)
38 | sourceText = myFileStream.GetFileTextFromStream()
39 | End Using
40 |
41 | Dim lines() As String = sourceText.SplitLines
42 | If mainForm.MenuOptionsColorizeSource.Checked Then
43 | Colorize(mainForm, GetClassifiedRanges(lines.Join(vbCrLf), LanguageNames.VisualBasic).ToList(), mainForm.ConversionOutput, lines.Length)
44 | mainForm.ConversionOutput.Select(0, 0)
45 | Else
46 | mainForm.ConversionOutput.Text = lines.Join(vbCrLf)
47 | End If
48 | mainForm.LineNumbersForConversionOutput.Visible = mainForm.MenuViewShowDestinationLineNumbers.Checked
49 | End Sub
50 |
51 | Friend Sub OpenSourceFile(mainForm As Form1, path As String)
52 | Dim lines As Integer = LoadInputBufferFromStream(mainForm, path)
53 | If lines = 0 Then
54 | mainForm.MenuConvertConvertSnippet.Enabled = False
55 | mainForm.MenuConvertConvertTopLevelStmts.Enabled = False
56 | If My.Settings.MRU_Data.Contains(path) Then
57 | My.Settings.MRU_Data.Remove(path)
58 | End If
59 | Else
60 | mainForm.MenuConvertConvertSnippet.Enabled = True
61 | mainForm.MenuConvertConvertTopLevelStmts.Enabled = True
62 | My.Settings.MRU_Data.MenuAddToMru(path)
63 | End If
64 | mainForm.MenuFile.DropDownItems.FileMenuMruUpdateUi(AddressOf mainForm.Menu_MRUList_Click)
65 | mainForm.UpdateLastFileMenu()
66 | End Sub
67 |
68 | End Module
69 |
--------------------------------------------------------------------------------
/CSharpToVB/Utilities/VisualStudioFileUtilities.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 |
7 | Public Module VisualStudioFileUtilities
8 | Private Const VisualStudioBaseName As String = "Visual Studio "
9 |
10 | Private Function GetUserDirectoryFromTemp() As String
11 | Dim sourceDirectory As String = FileIO.SpecialDirectories.Temp
12 | sourceDirectory = Directory.GetParent(sourceDirectory).FullName
13 | sourceDirectory = Directory.GetParent(sourceDirectory).FullName
14 | sourceDirectory = Directory.GetParent(sourceDirectory).FullName
15 | Return sourceDirectory
16 | End Function
17 |
18 | Public Function GetAlternateVisualStudioProjectsPath() As String
19 | Dim sourceDirectory As String = GetUserDirectoryFromTemp()
20 |
21 | If Directory.Exists(sourceDirectory) Then
22 | Dim reposPath As String = Path.Combine(sourceDirectory, "Source", "Repos")
23 | If Directory.Exists(reposPath) Then
24 | Return reposPath
25 | End If
26 | End If
27 | Return ""
28 | End Function
29 |
30 | Public Function GetLatestVisualStudioProjectPath() As String
31 | Dim directoryEntries As String() = Directory.GetDirectories(FileIO.SpecialDirectories.MyDocuments, VisualStudioBaseName.Trim & "*")
32 | Dim latestVersion As Integer = 0
33 | For Each dir As String In directoryEntries
34 | Dim directoryFileName As String = Path.GetFileName(dir)
35 | If directoryFileName.StartsWith(VisualStudioBaseName, StringComparison.OrdinalIgnoreCase) Then
36 | If Directory.Exists(Path.Combine(dir, "Projects")) Then
37 | Dim vsVersion As Integer = CInt(directoryFileName.Replace(VisualStudioBaseName, "", StringComparison.OrdinalIgnoreCase))
38 | If vsVersion > latestVersion Then
39 | latestVersion = vsVersion
40 | End If
41 | End If
42 | End If
43 | Next
44 | If latestVersion = 0 Then
45 | Return FileIO.SpecialDirectories.MyDocuments
46 | End If
47 | Return Path.Combine(FileIO.SpecialDirectories.MyDocuments, $"{VisualStudioBaseName}{latestVersion:0000}", "Projects")
48 | End Function
49 |
50 | End Module
51 |
--------------------------------------------------------------------------------
/CodeConverter/CodeConverter.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | net6.0-windows7.0
6 | Text
7 | On
8 | On
9 | On
10 | VB.CodeConverter
11 |
12 |
13 |
14 | en-US
15 | Paul M Cohen
16 | Travel By Paul
17 | VB Core Code Converter
18 | https://github.com/paul1956/CSharpToVB
19 | git
20 | 5.0.2.11
21 | 5.0.2.11
22 | 5.0.2.11
23 | Copyright (c) .NET Foundation and Contributors
24 | true
25 | License.txt
26 |
27 |
28 |
29 |
30 | all
31 | runtime; build; native; contentfiles; analyzers; buildtransitive
32 |
33 |
34 | all
35 | runtime; build; native; contentfiles; analyzers; buildtransitive
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | True
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/CodeConverter/CodeConverter.vbproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
4 | True
--------------------------------------------------------------------------------
/CodeConverter/Extensions/EnumExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Diagnostics.CodeAnalysis
6 | Imports System.Runtime.CompilerServices
7 |
8 | '''
9 | ''' This code is currently not used but is left here for future purposes
10 | '''
11 |
12 | Public Module EnumExtensions
13 |
14 | Private Sub CheckIsEnum(Of T)(withFlags As Boolean)
15 | If Not GetType(T).IsEnum Then
16 | Throw New ArgumentException(String.Format(Globalization.CultureInfo.InvariantCulture, "Type '{0}' is not an enum", GetType(T).FullName))
17 | End If
18 | If withFlags AndAlso Not Attribute.IsDefined(GetType(T), GetType(FlagsAttribute)) Then
19 | Throw New ArgumentException(String.Format(Globalization.CultureInfo.InvariantCulture, "Type '{0}' doesn't have the 'Flags' attribute", GetType(T).FullName))
20 | End If
21 | End Sub
22 |
23 | '
24 | 'Public Function ClearFlags(Of T As Structure)(value As T, flags As T) As T
25 | ' Return value.SetFlags(flags, False)
26 | 'End Function
27 |
28 | '
29 | 'Public Function ClearFlags(Of T As Structure)(value As T) As T
30 | ' CheckIsEnum(Of T)(withFlags:=True)
31 | ' For Each flag As T In [Enum].GetValues(GetType(T)).Cast(Of T)()
32 | ' value = value.ClearFlags(flag)
33 | ' Next flag
34 | ' Return value
35 | 'End Function
36 |
37 |
38 | Public Function CombineFlags(Of T As Structure)(flags As IEnumerable(Of T)) As T
39 | If flags Is Nothing Then
40 | Throw New ArgumentNullException(NameOf(flags))
41 | End If
42 | CheckIsEnum(Of T)(withFlags:=True)
43 | Dim lValue As Long = 0
44 | For Each flag As T In flags
45 | Dim lFlag As Long = Convert.ToInt64(flag, Globalization.CultureInfo.InvariantCulture)
46 | lValue = lValue Or lFlag
47 | Next flag
48 | Return DirectCast([Enum].ToObject(GetType(T), lValue), T)
49 | End Function
50 |
51 | '
52 | 'Public Function GetDescription(Of T As Structure)(value As T) As String
53 | ' CheckIsEnum(Of T)(withFlags:=False)
54 | ' Dim name As String = [Enum].GetName(GetType(T), value)
55 | ' If name IsNot Nothing Then
56 | ' Dim field As FieldInfo = GetType(T).GetField(name)
57 | ' If field IsNot Nothing Then
58 | ' Dim attribute As DescriptionAttribute = TryCast(Attribute.GetCustomAttribute(field, GetType(DescriptionAttribute)), DescriptionAttribute)
59 | ' If attribute IsNot Nothing Then
60 | ' Return attribute.Description
61 | ' End If
62 | ' End If
63 | ' End If
64 | ' Return Nothing
65 | 'End Function
66 |
67 | '
68 | 'Public Iterator Function GetFlags(Of T As Structure)(value As T) As IEnumerable(Of T)
69 | ' CheckIsEnum(Of T)(withFlags:=True)
70 | ' For Each flag As T In [Enum].GetValues(GetType(T)).Cast(Of T)()
71 | ' If value.IsFlagSet(flag) Then
72 | ' Yield flag
73 | ' End If
74 | ' Next flag
75 | 'End Function
76 |
77 |
78 | Public Function IsFlagSet(Of T As Structure)(value As T, flag As T) As Boolean
79 | CheckIsEnum(Of T)(withFlags:=True)
80 | Dim lValue As Long = Convert.ToInt64(value, Globalization.CultureInfo.InvariantCulture)
81 | Dim lFlag As Long = Convert.ToInt64(flag, Globalization.CultureInfo.InvariantCulture)
82 | Return (lValue And lFlag) <> 0
83 | End Function
84 |
85 | '
86 | 'Public Function SetFlags(Of T As Structure)(value As T, flags As T, [on] As Boolean) As T
87 | ' CheckIsEnum(Of T)(withFlags:=True)
88 | ' Dim lValue As Long = Convert.ToInt64(value, Globalization.CultureInfo.InvariantCulture)
89 | ' Dim lFlag As Long = Convert.ToInt64(flags, Globalization.CultureInfo.InvariantCulture)
90 | ' If [on] Then
91 | ' lValue = lValue Or lFlag
92 | ' Else
93 | ' lValue = lValue And (Not lFlag)
94 | ' End If
95 | ' Return DirectCast([Enum].ToObject(GetType(T), lValue), T)
96 | 'End Function
97 |
98 | '
99 | 'Public Function SetFlags(Of T As Structure)(value As T, flags As T) As T
100 | ' Return value.SetFlags(flags, True)
101 | 'End Function
102 |
103 | End Module
104 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/EnumerableExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 |
7 | Public Module EnumerableExtensions
8 |
9 | Private Function ContainsTypeName(inStr As String, target As String, comparison As StringComparison) As Boolean
10 | Dim s As String = inStr.Split(".").LastOrDefault()
11 | Return s.Equals(target, comparison)
12 | End Function
13 |
14 |
15 | Friend Function Contains(Of T)(sequence As IEnumerable(Of T), predicate As Func(Of T, Boolean)) As Boolean
16 | Return sequence.Any(predicate)
17 | End Function
18 |
19 | '''
20 | ''' This special Contains function compares a list of strings with additional functionality
21 | '''
22 | ''' The IEnumerable(Of String) that is searched
23 | ''' The string being com
24 | '''
25 | '''
26 |
27 | Friend Function Contains(sequence As IEnumerable(Of String), target As String, compareTypeOnly As Boolean, comparison As StringComparison) As Boolean
28 | If sequence Is Nothing Then Return False
29 | Dim predicate1 As Func(Of String, Boolean) = Function(inStr As String) As Boolean
30 | If compareTypeOnly Then
31 | Return ContainsTypeName(inStr, target, comparison)
32 | End If
33 | Return inStr.Equals(target, comparison)
34 | End Function
35 | Return sequence.Any(predicate1)
36 | End Function
37 |
38 | '''
39 | ''' This special FindAll function compares a list of strings with additional functionality
40 | '''
41 | ''' The IEnumerable(Of String) that is searched
42 | ''' The string being com
43 | '''
44 | '''
45 | '''
46 |
47 | Friend Function FindAll(sequence As List(Of String), target As String, compareTypeOnly As Boolean, comparison As StringComparison) As List(Of String)
48 | If sequence Is Nothing Then Return New List(Of String)
49 | Dim results As New List(Of String)
50 | Dim predicate1 As Func(Of String, Boolean) = Function(inStr As String) As Boolean
51 | If compareTypeOnly Then
52 | Return ContainsTypeName(inStr, target, comparison)
53 | End If
54 | Return inStr.Equals(target, comparison)
55 | End Function
56 |
57 | For Each s As String In sequence
58 | If predicate1(s) Then
59 | results.Add(s)
60 | End If
61 | Next
62 | Return results
63 | End Function
64 |
65 | End Module
66 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/ForEachExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 |
7 | Public Module ForEachExtensions
8 |
9 |
10 | Public Iterator Function WithIndex(Of T)(
11 | source As IEnumerable(Of T)
12 | ) As IEnumerable(Of IndexClass(Of T))
13 | If source Is Nothing Then
14 | Throw New ArgumentNullException(NameOf(source))
15 | End If
16 |
17 | Using enumerator As IEnumerator(Of T) = source.GetEnumerator
18 | Dim hasNext As Boolean = enumerator.MoveNext
19 | Dim index As Integer = -1
20 | While hasNext
21 | Dim wi As New IndexClass(Of T) With {.Index = index, .Enumerator = enumerator}
22 | wi.MoveNext()
23 | Yield wi
24 | hasNext = Not wi.IsLast
25 | index = wi.Index ' if .MoveNext was used
26 | End While
27 | End Using
28 | End Function
29 |
30 | End Module
31 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/IndexClass.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class IndexClass(Of T)
6 | Public Property Value As T
7 | Public Property Index As Integer ' first element has index = 0
8 |
9 | Public ReadOnly Property IsFirst As Boolean
10 | Get
11 | Return Me.Index = 0
12 | End Get
13 | End Property
14 |
15 | Public Property IsLast As Boolean
16 | Public Property Enumerator As IEnumerator(Of T)
17 |
18 | Public Sub MoveNext()
19 | Me.Value = Me.Enumerator.Current
20 | Me.IsLast = Not Me.Enumerator.MoveNext()
21 | ' may be called with .AsParallel
22 | Threading.Interlocked.Increment(Me.Index)
23 | End Sub
24 |
25 | End Class
26 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/StringExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports System.Text
7 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
8 |
9 | Public Module StringExtensions
10 |
11 |
12 | Friend Function ConvertCondition(condition As String) As String
13 | Return condition.
14 | Replace("==", "=", StringComparison.Ordinal).
15 | Replace("!=", "Not ", StringComparison.Ordinal).
16 | Replace("&&", "And", StringComparison.Ordinal).
17 | Replace("||", "Or", StringComparison.Ordinal).
18 | Replace("!", "Not ", StringComparison.Ordinal).
19 | Replace("false", "False", StringComparison.Ordinal).
20 | Replace("true", "True", StringComparison.Ordinal).
21 | Replace(" ", " ", StringComparison.Ordinal).
22 | Replace("//", " ' ", StringComparison.Ordinal)
23 | End Function
24 |
25 |
26 | Friend Function GetSafeVbName(expressionString As String) As String
27 | Dim expressionBuilder As New StringBuilder
28 | For Each e As IndexClass(Of Char) In expressionString.
29 | Replace(".", "Dot_", StringComparison.Ordinal).
30 | Replace(",", "Comma_", StringComparison.Ordinal).
31 | Replace("""", "Quote", StringComparison.Ordinal).
32 | Replace("[", "OpenBracket_", StringComparison.Ordinal).
33 | Replace("]", "CloseBracket", StringComparison.Ordinal).
34 | Replace("(", "OpenParen_", StringComparison.Ordinal).
35 | Replace(")", "CloseParen", StringComparison.Ordinal).
36 | Replace(" ", "_", StringComparison.Ordinal).WithIndex
37 | If e.IsFirst AndAlso Not VB.SyntaxFacts.IsIdentifierStartCharacter(e.Value) Then
38 | expressionBuilder.Append($"_")
39 | End If
40 | If VB.SyntaxFacts.IsIdentifierPartCharacter(e.Value) Then
41 | expressionBuilder.Append(e.Value)
42 | Else
43 | expressionBuilder.Append("_"c)
44 | End If
45 | Next
46 | Return expressionBuilder.ToString.TrimEnd("_"c)
47 | End Function
48 |
49 | ' String isn't IEnumerable in the current Portable profile.
50 |
51 | Friend Function Last(arg As String) As Char
52 | If String.IsNullOrEmpty(arg) Then
53 | Return CChar(vbNullChar)
54 | End If
55 | Return arg(arg.Length - 1)
56 | End Function
57 |
58 |
59 | Friend Function RemoveAll(input As String, ParamArray stringsToBeRemoved() As String) As String
60 | For Each s As String In stringsToBeRemoved
61 | input = input.Replace(s, "", StringComparison.Ordinal)
62 | Next
63 | Return input
64 | End Function
65 |
66 |
67 | Friend Function RemoveAll(input As String, stringsToBeRemoved As String) As String
68 | Return input.Replace(stringsToBeRemoved, "", StringComparison.Ordinal)
69 | End Function
70 |
71 |
72 | Friend Function RemoveBrackets(input As String) As String
73 | Return input.Replace("["c, "", StringComparison.Ordinal).
74 | Replace("]"c, "", StringComparison.Ordinal)
75 | End Function
76 |
77 |
78 | Friend Function WithoutLeadingSystemDot(input As String) As String
79 | If Not input.StartsWith("System.", StringComparison.Ordinal) Then
80 | Return input
81 | End If
82 | Return input.Substring("System.".Length)
83 | End Function
84 |
85 | End Module
86 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/SymbolInfoExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports Microsoft.CodeAnalysis
7 |
8 | Public Module SymbolInfoExtensions
9 |
10 |
11 | Friend Function GetAnySymbol(info As SymbolInfo) As ISymbol
12 | Return If(info.Symbol, info.CandidateSymbols.FirstOrDefault())
13 | End Function
14 |
15 | End Module
16 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/SyntaxExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports Microsoft.CodeAnalysis
7 | Imports CS = Microsoft.CodeAnalysis.CSharp
8 |
9 | Public Module SyntaxExtensions
10 |
11 |
12 | Friend Function IsParentKind(node As SyntaxNode, kind As CS.SyntaxKind) As Boolean
13 | Return node IsNot Nothing AndAlso node.Parent.IsKind(kind)
14 | End Function
15 |
16 | '''
17 | ''' Creates a new syntax node with all whitespace and end of line trivia replaced with
18 | ''' regularly formatted trivia
19 | '''
20 | ''' >The type of the node.
21 | ''' The node to format.
22 | '''
23 | ''' An optional sequence of whitespace characters that defines a single level of indentation.
24 | '''
25 | '''
26 | '''
27 |
28 | Public Function NormalizeWhitespaceEx(Of TNode As SyntaxNode)(node As TNode,
29 | useDefaultCasing As Boolean,
30 | Optional indentation As String = " ",
31 | Optional eol As String = vbCrLf,
32 | Optional preserveCRLF As Boolean = False
33 | ) As TNode
34 | If node Is Nothing Then
35 | Throw New ArgumentNullException(NameOf(node))
36 | End If
37 |
38 | Return DirectCast(SyntaxNormalizer.Normalize(node, indentation, eol, useElasticTrivia:=False, useDefaultCasing, preserveCRLF), TNode)
39 | End Function
40 |
41 | End Module
42 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/SyntaxNodeVBExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports Microsoft.CodeAnalysis
7 | Imports CS = Microsoft.CodeAnalysis.CSharp
8 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
9 |
10 | Friend Module SyntaxNodeVbExtensions
11 |
12 |
13 | Friend Function [With](Of T As VB.VisualBasicSyntaxNode)(node As T, leadingTrivia As IEnumerable(Of SyntaxTrivia), trailingTrivia As IEnumerable(Of SyntaxTrivia)) As T
14 | Return node.WithLeadingTrivia(leadingTrivia).WithTrailingTrivia(trailingTrivia)
15 | End Function
16 |
17 |
18 | Friend Function WithUniqueLeadingTrivia(Of T As VB.VisualBasicSyntaxNode)(node As T, headerLeadingTrivia As SyntaxTriviaList) As T
19 | Dim nodeLeadingTrivia As SyntaxTriviaList = node.GetLeadingTrivia
20 | If nodeLeadingTrivia.Count = 0 Then
21 | Return node
22 | End If
23 | If nodeLeadingTrivia.First.Language = "C#" Then
24 | nodeLeadingTrivia = nodeLeadingTrivia.ConvertTriviaList
25 | End If
26 | If headerLeadingTrivia.Count = 0 Then
27 | Return node
28 | End If
29 |
30 | If Not nodeLeadingTrivia.ContainsCommentOrDirectiveTrivia Then
31 | Return node
32 | End If
33 | Dim index As Integer
34 | For index = 0 To headerLeadingTrivia.Count - 1
35 | If headerLeadingTrivia(index).RawKind <> nodeLeadingTrivia(index).RawKind Then
36 | Exit For
37 | End If
38 | If headerLeadingTrivia(index).ToString <> nodeLeadingTrivia(index).ToString Then
39 | Exit For
40 | End If
41 | Next
42 | Dim newLeadingTrivia As New SyntaxTriviaList
43 | For i As Integer = index To nodeLeadingTrivia.Count - 1
44 | If i <> 0 AndAlso i = index AndAlso nodeLeadingTrivia(i).IsKind(CS.SyntaxKind.EndOfLineTrivia) Then
45 | Continue For
46 | End If
47 | newLeadingTrivia = newLeadingTrivia.Add(nodeLeadingTrivia(i))
48 | Next
49 | Return node.WithLeadingTrivia(newLeadingTrivia)
50 | End Function
51 |
52 | End Module
53 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/SyntaxTreeExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 | Imports System.Runtime.CompilerServices
7 | Imports System.Threading
8 | Imports Microsoft.CodeAnalysis
9 | Imports CS = Microsoft.CodeAnalysis.CSharp
10 | Imports CSS = Microsoft.CodeAnalysis.CSharp.Syntax
11 |
12 | Public Module SyntaxTreeExtensions
13 | Private ReadOnly s_autoGeneratedStrings() As String = {"< AutoGenerated", "
67 | Friend Function HasUsingDirective(tree As CS.CSharpSyntaxTree, fullName As String) As Boolean
68 | If tree Is Nothing Then
69 | Throw New ArgumentNullException(NameOf(tree))
70 | End If
71 | If String.IsNullOrWhiteSpace(fullName) Then
72 | Throw New ArgumentNullException(NameOf(fullName))
73 | End If
74 | fullName = fullName.Trim()
75 | Return tree.GetRoot().DescendantNodes(AddressOf MatchesNamespaceOrRoot).OfType(Of CSS.UsingDirectiveSyntax).Any(Function(u As CSS.UsingDirectiveSyntax) u.Name.ToString().Equals(fullName, StringComparison.OrdinalIgnoreCase))
76 | End Function
77 |
78 |
79 | Public Function IsGeneratedCode(tree As SyntaxTree, isComment As Func(Of SyntaxTrivia, Boolean), cancelToken As CancellationToken) As Boolean
80 | If isComment Is Nothing Then
81 | Throw New ArgumentNullException(NameOf(isComment))
82 | End If
83 |
84 | If tree Is Nothing Then
85 | Throw New ArgumentNullException(NameOf(tree))
86 | End If
87 | Return IsGeneratedCodeFile(tree.GetRoot(cancelToken).ToFullString) OrElse BeginsWithAutoGeneratedComment(tree, isComment, cancelToken)
88 | End Function
89 | End Module
90 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/TokenListExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports Microsoft.CodeAnalysis
7 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
8 |
9 | Friend Module TokenListExtensions
10 |
11 |
12 | Friend Function Contains(tokens As SyntaxTokenList, kind As CSharp.SyntaxKind) As Boolean
13 | Return tokens.Contains(Function(m As SyntaxToken) m.IsKind(kind))
14 | End Function
15 |
16 |
17 | Friend Function Contains(tokens As IEnumerable(Of SyntaxToken), ParamArray kind() As VB.SyntaxKind) As Boolean
18 | Return tokens.Contains(Function(m As SyntaxToken) m.IsKind(kind))
19 | End Function
20 |
21 |
22 | Friend Function IndexOf(tokens As IEnumerable(Of SyntaxToken), kind As VB.SyntaxKind) As Integer
23 | For i As Integer = 0 To tokens.Count - 1
24 | If tokens(i).IsKind(kind) Then
25 | Return i
26 | End If
27 | Next
28 | Return -1
29 | End Function
30 |
31 | End Module
32 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/TypeExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports Microsoft.CodeAnalysis
7 | Imports VBS = Microsoft.CodeAnalysis.VisualBasic.Syntax
8 |
9 | Public Module TypeExtensions
10 |
11 | '''
12 | ''' Gets all base classes and interfaces.
13 | '''
14 | ''' All classes and interfaces.
15 | ''' Type.
16 |
17 | Friend Iterator Function GetAllBaseClassesAndInterfaces(type As INamedTypeSymbol, Optional includeSuperType As Boolean = False) As IEnumerable(Of INamedTypeSymbol)
18 | If Not includeSuperType Then
19 | type = type.BaseType
20 | End If
21 | Dim curType As INamedTypeSymbol = type
22 | While curType IsNot Nothing
23 | Yield curType
24 | curType = curType.BaseType
25 | End While
26 |
27 | For Each inter As INamedTypeSymbol In type.AllInterfaces
28 | Yield inter
29 | Next
30 | End Function
31 |
32 |
33 | Friend Function GetElementType(typeSyntax As VBS.TypeSyntax) As VBS.TypeSyntax
34 | Dim arrayTypeSyntax As VBS.ArrayTypeSyntax = TryCast(typeSyntax, VBS.ArrayTypeSyntax)
35 | If arrayTypeSyntax IsNot Nothing Then
36 | typeSyntax = arrayTypeSyntax.ElementType
37 | End If
38 | Return typeSyntax
39 | End Function
40 |
41 | End Module
42 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/TypeInfoExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 | Imports Microsoft.CodeAnalysis
7 |
8 | Public Module TypeInfoExtensions
9 |
10 |
11 | Friend Function IsString(typeInfo As TypeInfo) As Boolean
12 | Dim typeSymbol As ITypeSymbol = typeInfo.Type
13 |
14 | If typeSymbol Is Nothing OrElse typeSymbol.IsErrorType Then
15 | Return False
16 | End If
17 |
18 | If typeSymbol.ToString.RemoveAll("?").Equals("string", StringComparison.OrdinalIgnoreCase) Then
19 | Return True
20 | End If
21 |
22 | Return False
23 | End Function
24 |
25 | End Module
26 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/TypeSwitchExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Runtime.CompilerServices
6 |
7 | Friend Module TypeSwitchExtensions
8 |
9 | #Region "TypeSwitch on Action"
10 |
11 |
12 | Friend Sub TypeSwitch(Of TBaseType, TDerivedType1 As TBaseType, TDerivedType2 As TBaseType, TDerivedType3 As TBaseType)(obj As TBaseType, matchAction1 As Action(Of TDerivedType1), matchAction2 As Action(Of TDerivedType2), matchAction3 As Action(Of TDerivedType3), Optional defaultAction As Action(Of TBaseType) = Nothing)
13 | If TypeOf obj Is TDerivedType1 Then
14 | matchAction1(DirectCast(obj, TDerivedType1))
15 | ElseIf TypeOf obj Is TDerivedType2 Then
16 | matchAction2(DirectCast(obj, TDerivedType2))
17 | ElseIf TypeOf obj Is TDerivedType3 Then
18 | matchAction3(DirectCast(obj, TDerivedType3))
19 | ElseIf defaultAction IsNot Nothing Then
20 | defaultAction(obj)
21 | End If
22 | End Sub
23 |
24 | #End Region
25 |
26 | #Region "TypeSwitch on Func"
27 |
28 |
29 | Friend Function TypeSwitch(Of TBaseType, TDerivedType1 As TBaseType, TDerivedType2 As TBaseType, TDerivedType3 As TBaseType, TResult)(obj As TBaseType, matchFunc1 As Func(Of TDerivedType1, TResult), matchFunc2 As Func(Of TDerivedType2, TResult), matchFunc3 As Func(Of TDerivedType3, TResult), Optional defaultFunc As Func(Of TBaseType, TResult) = Nothing) As TResult
30 | If TypeOf obj Is TDerivedType1 Then
31 | Return matchFunc1(DirectCast(obj, TDerivedType1))
32 | ElseIf TypeOf obj Is TDerivedType2 Then
33 | Return matchFunc2(DirectCast(obj, TDerivedType2))
34 | ElseIf TypeOf obj Is TDerivedType3 Then
35 | Return matchFunc3(DirectCast(obj, TDerivedType3))
36 | ElseIf defaultFunc IsNot Nothing Then
37 | Return defaultFunc(obj)
38 | Else
39 | Return Nothing
40 | End If
41 | End Function
42 |
43 |
44 | Friend Function TypeSwitch(Of TBaseType, TDerivedType1 As TBaseType, TDerivedType2 As TBaseType, TDerivedType3 As TBaseType, TDerivedType4 As TBaseType, TDerivedType5 As TBaseType,
45 | TResult)(obj As TBaseType, matchFunc1 As Func(Of TDerivedType1, TResult), matchFunc2 As Func(Of TDerivedType2, TResult), matchFunc3 As Func(Of TDerivedType3, TResult), matchFunc4 As Func(Of TDerivedType4, TResult), matchFunc5 As Func(Of TDerivedType5, TResult),
46 | Optional defaultFunc As Func(Of TBaseType, TResult) = Nothing) As TResult
47 | If TypeOf obj Is TDerivedType1 Then
48 | Return matchFunc1(DirectCast(obj, TDerivedType1))
49 | ElseIf TypeOf obj Is TDerivedType2 Then
50 | Return matchFunc2(DirectCast(obj, TDerivedType2))
51 | ElseIf TypeOf obj Is TDerivedType3 Then
52 | Return matchFunc3(DirectCast(obj, TDerivedType3))
53 | ElseIf TypeOf obj Is TDerivedType4 Then
54 | Return matchFunc4(DirectCast(obj, TDerivedType4))
55 | ElseIf TypeOf obj Is TDerivedType5 Then
56 | Return matchFunc5(DirectCast(obj, TDerivedType5))
57 | ElseIf defaultFunc IsNot Nothing Then
58 | Return defaultFunc(obj)
59 | Else
60 | Return Nothing
61 | End If
62 | End Function
63 |
64 |
65 | Friend Function TypeSwitch(Of TBaseType, TDerivedType1 As TBaseType, TDerivedType2 As TBaseType, TDerivedType3 As TBaseType, TDerivedType4 As TBaseType, TDerivedType5 As TBaseType,
66 | TDerivedType6 As TBaseType, TDerivedType7 As TBaseType, TResult)(obj As TBaseType, matchFunc1 As Func(Of TDerivedType1, TResult), matchFunc2 As Func(Of TDerivedType2, TResult), matchFunc3 As Func(Of TDerivedType3, TResult), matchFunc4 As Func(Of TDerivedType4, TResult), matchFunc5 As Func(Of TDerivedType5, TResult),
67 | matchFunc6 As Func(Of TDerivedType6, TResult), matchFunc7 As Func(Of TDerivedType7, TResult), Optional defaultFunc As Func(Of TBaseType, TResult) = Nothing) As TResult
68 | If TypeOf obj Is TDerivedType1 Then
69 | Return matchFunc1(DirectCast(obj, TDerivedType1))
70 | ElseIf TypeOf obj Is TDerivedType2 Then
71 | Return matchFunc2(DirectCast(obj, TDerivedType2))
72 | ElseIf TypeOf obj Is TDerivedType3 Then
73 | Return matchFunc3(DirectCast(obj, TDerivedType3))
74 | ElseIf TypeOf obj Is TDerivedType4 Then
75 | Return matchFunc4(DirectCast(obj, TDerivedType4))
76 | ElseIf TypeOf obj Is TDerivedType5 Then
77 | Return matchFunc5(DirectCast(obj, TDerivedType5))
78 | ElseIf TypeOf obj Is TDerivedType6 Then
79 | Return matchFunc6(DirectCast(obj, TDerivedType6))
80 | ElseIf TypeOf obj Is TDerivedType7 Then
81 | Return matchFunc7(DirectCast(obj, TDerivedType7))
82 | ElseIf defaultFunc IsNot Nothing Then
83 | Return defaultFunc(obj)
84 | Else
85 | Return Nothing
86 | End If
87 | End Function
88 |
89 | #End Region
90 |
91 | End Module
92 |
--------------------------------------------------------------------------------
/CodeConverter/Extensions/TypeSymbolExtensions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.ComponentModel
6 | Imports System.Runtime.CompilerServices
7 | Imports System.Text
8 | Imports Microsoft.CodeAnalysis
9 | Imports Factory = Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory
10 | Imports VBS = Microsoft.CodeAnalysis.VisualBasic.Syntax
11 |
12 |
13 | Public Module TypeSymbolExtensions
14 |
15 |
16 | Private Function GetFullMetadataName(ns As INamespaceSymbol) As String
17 | Dim sb As New StringBuilder
18 | While ns IsNot Nothing AndAlso Not ns.IsGlobalNamespace
19 | If sb.Length > 0 Then
20 | sb.Insert(0, "."c)
21 | End If
22 | sb.Insert(0, ns.MetadataName)
23 | ns = ns.ContainingNamespace
24 | End While
25 |
26 | Return sb.ToString()
27 | End Function
28 |
29 |
30 | Friend Function GetFullyQualifiedNameSyntax(symbol As INamespaceOrTypeSymbol) As VBS.NameSyntax
31 | Select Case True
32 | Case TypeOf symbol Is ITypeSymbol
33 | Dim typeSyntax As VBS.TypeSyntax = CType(symbol, ITypeSymbol).ConvertToType.GetElementType
34 | If TypeOf typeSyntax Is VBS.PredefinedTypeSyntax Then
35 | typeSyntax = Factory.IdentifierName($"[{symbol}]")
36 | End If
37 | Dim nullableType As VBS.NullableTypeSyntax = TryCast(typeSyntax, VBS.NullableTypeSyntax)
38 | If nullableType IsNot Nothing Then
39 | typeSyntax = nullableType.ElementType
40 | End If
41 | Return CType(typeSyntax, VBS.NameSyntax)
42 | Case TypeOf symbol Is INamespaceSymbol
43 | Dim ns As INamespaceSymbol = CType(symbol, INamespaceSymbol)
44 | Return Factory.ParseName(ns.GetFullMetadataName())
45 | Case Else
46 | Throw New NotImplementedException($"Fully qualified name for {symbol.[GetType]().FullName} not implemented")
47 | End Select
48 | End Function
49 |
50 |
51 | Friend Function IsDelegateType(symbol As ITypeSymbol) As Boolean
52 | If symbol Is Nothing Then
53 | Return False
54 | End If
55 | Return symbol.TypeKind = TypeKind.Delegate
56 | End Function
57 |
58 |
59 | Friend Function IsErrorType(symbol As ITypeSymbol) As Boolean
60 | Return CBool(symbol?.TypeKind = TypeKind.Error)
61 | End Function
62 |
63 |
64 | Friend Function IsInterfaceType(symbol As ITypeSymbol) As Boolean
65 | If symbol Is Nothing Then
66 | Return False
67 | End If
68 |
69 | Return symbol.TypeKind = TypeKind.Interface
70 | End Function
71 |
72 | End Module
73 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/CodeWithOptions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports CS = Microsoft.CodeAnalysis.CSharp
7 |
8 | Public Class CodeWithOptions
9 |
10 | Friend Sub New(requestToConvert As ConvertRequest)
11 | If requestToConvert Is Nothing Then
12 | Throw New ArgumentNullException(NameOf(requestToConvert))
13 | End If
14 | Me.Text = requestToConvert.SourceCode
15 | Me.FromLanguage = LanguageNames.CSharp
16 | Me.ToLanguage = LanguageNames.VisualBasic
17 | Me.FromLanguageVersion = CS.LanguageVersion.Latest
18 | Me.ToLanguageVersion = VisualBasic.LanguageVersion.Latest
19 | Me.Request = requestToConvert
20 | End Sub
21 |
22 | Friend Property FromLanguage As String
23 | Friend Property FromLanguageVersion As Integer
24 | Friend Property Request As ConvertRequest
25 | Friend Property Text As String
26 | Friend Property ToLanguage() As String
27 | Friend Property ToLanguageVersion() As Integer
28 |
29 | Friend Function SetFromLanguageVersion(Optional version As Integer = CS.LanguageVersion.Latest) As CodeWithOptions
30 | Me.FromLanguageVersion = version
31 | Return Me
32 | End Function
33 |
34 | Friend Function SetToLanguageVersion(Optional version As Integer = VisualBasic.LanguageVersion.Latest) As CodeWithOptions
35 | Me.ToLanguageVersion = version
36 | Return Me
37 | End Function
38 |
39 | End Class
40 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/CommonConversions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports CS = Microsoft.CodeAnalysis.CSharp
7 |
8 | Friend NotInheritable Class CommonConversions
9 | Private ReadOnly _semanticModel As SemanticModel
10 |
11 | Friend Sub New(semanticModel1 As SemanticModel)
12 | _semanticModel = semanticModel1
13 | End Sub
14 |
15 | Private Function GetSymbol(syntax As CS.CSharpSyntaxNode) As ISymbol
16 | Return If(syntax.SyntaxTree Is _semanticModel.SyntaxTree, _semanticModel.GetSymbolInfo(syntax).Symbol, Nothing)
17 | End Function
18 |
19 | Friend Function IsEventHandlerIdentifier(syntax As CS.CSharpSyntaxNode) As Boolean
20 | Return Me.GetSymbol(syntax).IsKind(SymbolKind.Event)
21 | End Function
22 |
23 | End Class
24 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/ConversionResult.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports Microsoft.CodeAnalysis.Formatting
7 | Imports Microsoft.CodeAnalysis.Options
8 | Imports Microsoft.CodeAnalysis.Text
9 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
10 |
11 | Public Class ConversionResult
12 |
13 | Private _filteredListOfFailures As List(Of Diagnostic)
14 |
15 | Friend Sub New(convertedTree As SyntaxNode, inputLanguage As String, outputLanguage As String, vbPreprocessorSymbols As List(Of KeyValuePair(Of String, Object)))
16 | Me.Exceptions = New List(Of Exception)
17 | Me.SourceLanguage = inputLanguage
18 | Me.ResultStatus = ResultTriState.Success
19 | Me.TargetLanguage = outputLanguage
20 | Using workspace As New AdhocWorkspace()
21 | Dim project As Project = workspace.CurrentSolution.AddProject("Project", "Project.dll", outputLanguage).WithParseOptions(GetVbParseOptions(vbPreprocessorSymbols))
22 | Dim syntaxTree As SyntaxTree = project.AddDocument("Document", convertedTree).GetSyntaxTreeAsync().Result
23 | Dim root As SyntaxNode = syntaxTree.GetRootAsync().GetAwaiter.GetResult
24 | Try
25 | Me.ConvertedCode = WorkspaceFormat(workspace, root, spans:=Nothing, workspace.Options, project.AddDocument("Document", convertedTree).GetTextAsync().GetAwaiter.GetResult)
26 | Me.ConvertedTree = DirectCast(root, VB.VisualBasicSyntaxNode)
27 | Exit Sub
28 | Catch ex As Exception
29 | End Try
30 |
31 | Dim tree As SyntaxTree = VB.VisualBasicSyntaxTree.ParseText(root.NormalizeWhitespaceEx(useDefaultCasing:=True).ToFullString)
32 | Dim root1 As SyntaxNode = tree.GetRootAsync().GetAwaiter.GetResult
33 | Try
34 | Me.ConvertedCode = WorkspaceFormat(workspace, root1, spans:=Nothing, workspace.Options, project.AddDocument("Document", convertedTree).GetTextAsync().GetAwaiter.GetResult)
35 | Me.ConvertedTree = DirectCast(root1, VB.VisualBasicSyntaxNode)
36 | Catch ex As Exception
37 | Me.ConvertedCode = DirectCast(root, VB.VisualBasicSyntaxNode).ToFullString
38 | End Try
39 | Me.ConvertedTree = DirectCast(root1, VB.VisualBasicSyntaxNode)
40 | End Using
41 | End Sub
42 |
43 | Friend Sub New(ParamArray exceptions() As Exception)
44 | Me.ResultStatus = If(exceptions.Any, ResultTriState.Failure, ResultTriState.Ignore)
45 | Me.Exceptions = exceptions
46 | End Sub
47 |
48 | '''
49 | ''' Indicates File Conversion succeeded, failed or wasn't attempted (ignored)
50 | '''
51 | Public Enum ResultTriState
52 |
53 | ' This file was ignored setting.
54 | Ignore = -2
55 |
56 | ' Conversion succeeded.
57 | Success = -1
58 |
59 | ' Conversion failed.
60 | Failure = 0
61 |
62 | End Enum
63 |
64 | Public ReadOnly Property ConvertedCode As String
65 |
66 | Public Property ConvertedTree As VB.VisualBasicSyntaxNode
67 |
68 | Public Property Exceptions As IReadOnlyList(Of Exception)
69 | Public Property ResultStatus As ResultTriState
70 |
71 | Public Property SourceLanguage As String
72 |
73 | Public Property TargetLanguage As String
74 |
75 | Protected Shared Function WorkspaceFormat(workspace As Workspace, root As SyntaxNode, spans As IEnumerable(Of TextSpan), pOptionSet As OptionSet, pSourceText As SourceText) As String
76 | Dim result As IList(Of TextChange) = Formatter.GetFormattedTextChanges(root, spans, workspace, pOptionSet)
77 | Return pSourceText?.WithChanges(result).ToString()
78 | End Function
79 |
80 | Public Function GetFilteredListOfFailures() As List(Of Diagnostic)
81 | If _filteredListOfFailures IsNot Nothing Then
82 | For Each d As Diagnostic In _filteredListOfFailures
83 | If d.Id = "BC30689" Then
84 | Return New List(Of Diagnostic)
85 | End If
86 | Next
87 | End If
88 | Return _filteredListOfFailures
89 | End Function
90 |
91 | Public Sub SetFilteredListOfFailures(autoPropertyValue As List(Of Diagnostic))
92 | _filteredListOfFailures = autoPropertyValue
93 | End Sub
94 |
95 | End Class
96 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/ConvertRequest.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Collections.Immutable
6 | Imports System.Threading
7 | Imports Microsoft.CodeAnalysis
8 | Imports ProgressReportLibrary
9 |
10 | Public Class ConvertRequest
11 |
12 | Public Sub New(mSkipAutoGenerated As Boolean, isProjectConverstion As Boolean, mProgress As IProgress(Of ProgressReport), mCancelToken As CancellationToken)
13 | Me.SkipAutoGenerated = mSkipAutoGenerated
14 | Me.IsProjectConversion = isProjectConverstion
15 | Me.Progress = mProgress
16 | Me.CancelToken = mCancelToken
17 | Me.UsedStacks = New Stack(New Dictionary(Of String, SymbolTableEntry)(StringComparer.Ordinal))
18 | Me.ImplementedMembers = (New List(Of (type As INamedTypeSymbol, members As ImmutableArray(Of ISymbol)))).ToImmutableArray
19 | Me.ImplementedMembersStack = New Stack(ImmutableArray(Of (type As INamedTypeSymbol, members As ImmutableArray(Of ISymbol))).Empty)
20 | End Sub
21 |
22 |
23 | Public Property CancelToken As CancellationToken
24 | Public Property ImplementedMembers As ImmutableArray(Of (type As INamedTypeSymbol, members As ImmutableArray(Of ISymbol)))
25 | Public ReadOnly Property IsProjectConversion As Boolean
26 | Public ReadOnly Property ImplementedMembersStack As Stack
27 | Public ReadOnly Property Progress As IProgress(Of ProgressReport)
28 | Public ReadOnly Property SkipAutoGenerated As Boolean
29 | Public Property SourceCode As String
30 | Public ReadOnly Property UsedStacks As Stack
31 | End Class
32 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/DefaultVBOptions.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class DefaultVbOptions
6 |
7 | Public Sub New(optionCompare As String, optionCompareInclude As Boolean, optionExplicit As String, optionExplicitInclude As Boolean, optionInfer As String, optionInferInclude As Boolean, optionStrict As String, optionStrictInclude As Boolean)
8 | Me.OptionCompare = optionCompare
9 | Me.OptionCompareInclude = optionCompareInclude
10 | Me.OptionExplicit = optionExplicit
11 | Me.OptionExplicitInclude = optionExplicitInclude
12 | Me.OptionInfer = optionInfer
13 | Me.OptionInferInclude = optionInferInclude
14 | Me.OptionStrict = optionStrict
15 | Me.OptionStrictInclude = optionStrictInclude
16 | End Sub
17 |
18 | Public Sub New()
19 |
20 | End Sub
21 |
22 | Public ReadOnly Property OptionCompare As String = "Text"
23 | Public ReadOnly Property OptionCompareInclude As Boolean
24 | Public ReadOnly Property OptionExplicit As String = "Off"
25 | Public ReadOnly Property OptionExplicitInclude As Boolean = True
26 | Public ReadOnly Property OptionInfer As String = "On"
27 | Public ReadOnly Property OptionInferInclude As Boolean = True
28 | Public ReadOnly Property OptionStrict As String = "Off"
29 | Public ReadOnly Property OptionStrictInclude As Boolean = True
30 | End Class
31 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/StatementHandling.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
6 | Imports VBS = Microsoft.CodeAnalysis.VisualBasic.Syntax
7 |
8 | Public Class StatementHandling
9 |
10 | Public Sub New(index As Integer, statement As VB.VisualBasicSyntaxNode, statementHandling As StatementHandlingOption)
11 | _Index = index
12 | _VbNode = statement
13 | _HandlingOption = statementHandling
14 | End Sub
15 |
16 | Public Property HandlingOption As StatementHandlingOption
17 | Public Property Index As Integer
18 |
19 | Public ReadOnly Property Statement As VBS.StatementSyntax
20 | Get
21 | Return TryCast(_VbNode, VBS.StatementSyntax)
22 | End Get
23 | End Property
24 |
25 | Public Property VbNode As VB.VisualBasicSyntaxNode
26 | End Class
27 |
--------------------------------------------------------------------------------
/CodeConverter/SupportClasses/SymbolTableEntry.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Class SymbolTableEntry
6 |
7 | Friend Sub New(name As String, isType As Boolean, isProperty As Boolean)
8 | Me.Name = name
9 | Me.IsType = isType
10 | Me.IsProperty = isProperty
11 | End Sub
12 |
13 | Public ReadOnly Property IsProperty As Boolean
14 | Public ReadOnly Property IsType As Boolean
15 | Public ReadOnly Property Name As String
16 | End Class
17 |
--------------------------------------------------------------------------------
/CodeConverter/Utilities/CSharpSyntaxFactory.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports Microsoft.CodeAnalysis.CSharp
7 |
8 | Public Module CSharpSyntaxFactory
9 | Public ReadOnly s_csReadOnlyKeyword As SyntaxToken = SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)
10 | Public ReadOnly s_csEmptySpaceTrivia As SyntaxTrivia = SyntaxFactory.Whitespace(String.Empty)
11 |
12 | End Module
13 |
--------------------------------------------------------------------------------
/CodeConverter/Utilities/ExceptionUtilities.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Diagnostics.CodeAnalysis
6 | Imports System.Runtime.CompilerServices
7 |
8 |
9 | Public Module ExceptionUtilities
10 |
11 |
12 | Public ReadOnly Property UnreachableException( Optional memberName As String = Nothing,
13 | Optional sourceLineNumber As Integer = 0) As Exception
14 | Get
15 | Return New InvalidOperationException($"The program location {memberName} line {sourceLineNumber} is thought to be unreachable.")
16 | End Get
17 | End Property
18 |
19 |
20 | Friend Function UnexpectedValue(o As Object, Optional memberName As String = Nothing,
21 | Optional sourceLineNumber As Integer = 0) As Exception
22 |
23 | ' We do not throw from here because we don't want all Watson reports to be bucketed to this call.
24 | Return New InvalidOperationException($"Unexpected value '{o}' of type '{If(o Is Nothing, "", o.GetType().FullName)}' at {memberName} line {sourceLineNumber}")
25 | End Function
26 |
27 | End Module
28 |
--------------------------------------------------------------------------------
/CodeConverter/Utilities/IdentifierSupport.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.Text
6 | Imports CS = Microsoft.CodeAnalysis.CSharp
7 | Imports CSS = Microsoft.CodeAnalysis.CSharp.Syntax
8 | Imports Factory = Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory
9 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
10 | Imports VBS = Microsoft.CodeAnalysis.VisualBasic.Syntax
11 |
12 | Public Module IdentifierSupport
13 |
14 | Friend Sub CreateDesignationName(listOfVariables As List(Of VBS.ModifiedIdentifierSyntax), ByRef sBuilder As StringBuilder)
15 | sBuilder.Append("TupleTempVar")
16 | For j As Integer = 0 To listOfVariables.Count - 1
17 | Dim v As VBS.ModifiedIdentifierSyntax = listOfVariables(j)
18 | If v.Identifier.ValueText = "_" Then
19 | sBuilder.Append($"_Discard{j}")
20 | Else
21 | sBuilder.Append($"_{v.Identifier.ValueText}")
22 | End If
23 | Next
24 | End Sub
25 |
26 | Friend Function IsSpecialReservedWord(id As String) As Boolean
27 | If id.Equals("Alias", StringComparison.OrdinalIgnoreCase) OrElse
28 | id.Equals("CType", StringComparison.OrdinalIgnoreCase) OrElse
29 | id.Equals("End", StringComparison.OrdinalIgnoreCase) OrElse
30 | id.Equals("Error", StringComparison.OrdinalIgnoreCase) OrElse
31 | id.Equals("Event", StringComparison.OrdinalIgnoreCase) OrElse
32 | id.Equals("Imports", StringComparison.OrdinalIgnoreCase) OrElse
33 | id.Equals("Module", StringComparison.OrdinalIgnoreCase) OrElse
34 | id.Equals("Option", StringComparison.OrdinalIgnoreCase) OrElse
35 | id.Equals("Optional", StringComparison.OrdinalIgnoreCase) Then
36 | Return True
37 | End If
38 | Return False
39 | End Function
40 |
41 | '''
42 | ''' If id is an VB Reserved word surround with []
43 | '''
44 | '''
45 | Friend Function MakeVbSafeName(id As String) As String
46 | If IsSpecialReservedWord(id) OrElse
47 | VB.SyntaxFacts.IsKeywordKind(VB.SyntaxFacts.GetKeywordKind(id)) Then
48 | Return $"[{id}]"
49 | End If
50 | Return id
51 | End Function
52 |
53 | Friend Function ProcessVariableDesignation(node As CSS.ParenthesizedVariableDesignationSyntax) As List(Of VBS.ModifiedIdentifierSyntax)
54 | Dim vbVariables As New List(Of VBS.ModifiedIdentifierSyntax)
55 | For Each e As IndexClass(Of CSS.VariableDesignationSyntax) In node.Variables.WithIndex
56 | Dim vbVariableDeclarator As VBS.ModifiedIdentifierSyntax
57 | If e.Value.RawKind = CS.SyntaxKind.DiscardDesignation Then
58 | vbVariableDeclarator = Factory.ModifiedIdentifier("_")
59 | Else
60 | vbVariableDeclarator = Factory.ModifiedIdentifier(MakeVbSafeName(e.Value.ToString))
61 | End If
62 | vbVariables.Add(vbVariableDeclarator)
63 | Next
64 | Return vbVariables
65 | End Function
66 |
67 | End Module
68 |
--------------------------------------------------------------------------------
/CodeConverter/Utilities/ParseUtilities.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports Microsoft.CodeAnalysis
6 | Imports CS = Microsoft.CodeAnalysis.CSharp
7 | Imports VB = Microsoft.CodeAnalysis.VisualBasic
8 |
9 | Public Module ParseUtilities
10 |
11 | Private Function GetCSharpParseOptions(csPreprocessorSymbols As List(Of String)) As CS.CSharpParseOptions
12 | Return New CS.CSharpParseOptions(CS.LanguageVersion.Latest,
13 | DocumentationMode.Parse,
14 | SourceCodeKind.Script,
15 | csPreprocessorSymbols)
16 | End Function
17 |
18 | Friend Function GetVbParseOptions(vbPreprocessorSymbols As List(Of KeyValuePair(Of String, Object))) As VB.VisualBasicParseOptions
19 | Return New VB.VisualBasicParseOptions(VB.LanguageVersion.Latest,
20 | DocumentationMode.Diagnose,
21 | SourceCodeKind.Regular,
22 | vbPreprocessorSymbols)
23 | End Function
24 |
25 | Public Function ParseCSharpSource(sourceText As String, csPreprocessorSymbols As List(Of String)) As SyntaxTree
26 | Return CS.SyntaxFactory.ParseSyntaxTree(Text.SourceText.From(sourceText),
27 | GetCSharpParseOptions(csPreprocessorSymbols)
28 | )
29 | End Function
30 |
31 | End Module
32 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | latest
4 |
5 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) .NET Foundation and Contributors
4 |
5 | All rights reserved.
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/ObjectPoolLibrary/ObjectPoolLibrary.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | true
6 | Paul M Cohen
7 | Travel By Paul
8 | Copyright (c) .NET Foundation and Contributors
9 | https://github.com/paul1956/CSharpToVB
10 | Git
11 | en-US
12 | 1.0.0.2
13 | 1.0.0.2
14 | 1.0.0.2
15 | ObjectPool Library
16 |
17 |
18 |
19 |
20 |
21 | all
22 | runtime; build; native; contentfiles; analyzers; buildtransitive
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/ProgressReportLibrary/ProgressReport.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Public Structure ProgressReport
6 | Implements IEquatable(Of ProgressReport)
7 |
8 | Public Sub New(current As Integer, maximum As Integer)
9 | Me.Current = current
10 | Me.Maximum = maximum
11 | End Sub
12 |
13 | Public ReadOnly Property Current As Integer
14 | Public ReadOnly Property Maximum As Integer
15 |
16 | Public Overrides Function Equals(obj As Object) As Boolean
17 | Return (TypeOf obj Is ProgressReport) AndAlso Me.Equals(DirectCast(obj, ProgressReport))
18 | End Function
19 |
20 | Public Overloads Function Equals(other As ProgressReport) As Boolean Implements IEquatable(Of ProgressReport).Equals
21 | Return Me.Current = other.Current AndAlso Me.Maximum = other.Maximum
22 | End Function
23 |
24 | Public Overrides Function GetHashCode() As Integer
25 | Return HashCode.Combine(Me.Current, Me.Maximum)
26 | End Function
27 |
28 | Public Shared Operator =(left As ProgressReport, right As ProgressReport) As Boolean
29 | Return left.Equals(right)
30 | End Operator
31 |
32 | Public Shared Operator <>(left As ProgressReport, right As ProgressReport) As Boolean
33 | Return Not left = right
34 | End Operator
35 |
36 | End Structure
37 |
--------------------------------------------------------------------------------
/ProgressReportLibrary/ProgressReportLibrary.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProgressReportLibrary
5 | net6.0
6 | Paul M Cohen
7 | Travel by Paul
8 | Copyright (c) .NET Foundation and Contributors
9 | https://github.com/paul1956/CSharpToVB
10 | Git
11 | en-US
12 | Class used to pass around progress information
13 | 1.0.0.0
14 | 1.0.0.0
15 | Progress Report Library
16 |
17 |
18 |
19 |
20 |
21 | all
22 | runtime; build; native; contentfiles; analyzers; buildtransitive
23 |
24 |
25 | all
26 | runtime; build; native; contentfiles; analyzers; buildtransitive
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Releases/C#ToVB5.0.7.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paul1956/CSharpToVB/5f3b2f0430c4ec9d350ac83900ee98aad66265ed/Releases/C#ToVB5.0.7.0.zip
--------------------------------------------------------------------------------
/TestConsoleApp/AnalyzerAdditionalFile.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | ' See the LICENSE file in the project root for more information.
4 |
5 | Imports System.IO
6 | Imports Microsoft.CodeAnalysis
7 | Imports Microsoft.CodeAnalysis.Text
8 |
9 | Public NotInheritable Class AnalyzerAdditionalFile
10 | Inherits AdditionalText
11 |
12 | Public Sub New(path As String)
13 | Me.Path = path
14 | End Sub
15 |
16 | Public Overrides ReadOnly Property Path As String
17 |
18 | Public Overrides Function GetText(Optional cancellationToken As Threading.CancellationToken = Nothing) As Text.SourceText
19 | Return SourceText.From(File.ReadAllText(Me.Path))
20 | End Function
21 | End Class
22 |
--------------------------------------------------------------------------------
/TestConsoleApp/Program.vb:
--------------------------------------------------------------------------------
1 | Imports System.Collections.Immutable
2 | Imports System.Reflection
3 | Imports CVS_Generator
4 | Imports Microsoft.CodeAnalysis
5 | Imports Microsoft.CodeAnalysis.VisualBasic
6 |
7 | Module Program
8 |
9 | Public Sub Main()
10 | Dim source = s_LightModeColorDictionary.Count Then
17 | Throw New ApplicationException("s_DarkModeColorDictionary.Count <> s_LightModeColorDictionary.Count")
18 | End If
19 | End Sub
20 | End Class
21 |
22 | End Namespace]]>.Value
23 |
24 | Dim result = GetGeneratedOutput(source)
25 |
26 | If result.Diagnostics.Length > 0 Then
27 | Console.WriteLine("Diagnostics:")
28 | For Each diag In result.Diagnostics
29 | Console.WriteLine(" " & diag.ToString())
30 | Next
31 | Console.WriteLine()
32 | Console.WriteLine("Output:")
33 | End If
34 |
35 | Console.WriteLine(result.Output)
36 |
37 | End Sub
38 |
39 | Private Function GetGeneratedOutput(source As String) As (Diagnostics As ImmutableArray(Of Diagnostic), Output As String)
40 |
41 | Dim syntaxTree = VisualBasicSyntaxTree.ParseText(source)
42 |
43 | Dim references As List(Of MetadataReference) = New List(Of MetadataReference)
44 | Dim assemblies As Assembly() = AppDomain.CurrentDomain.GetAssemblies()
45 | For Each assembly As Assembly In assemblies
46 | If Not assembly.IsDynamic Then
47 | references.Add(MetadataReference.CreateFromFile(assembly.Location))
48 | End If
49 | Next
50 |
51 | Dim compilation = VisualBasicCompilation.Create("Foo", New SyntaxTree() {syntaxTree}, references, New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
52 |
53 | ' TODO: Uncomment these lines if you want to return immediately if the injected program isn't valid _before_ running generators
54 | '
55 | 'Dim compilationDiagnostics = compilation.GetDiagnostics()
56 | 'If compilationDiagnostics.Any() Then
57 | ' Return (compilationDiagnostics, "")
58 | 'End If
59 |
60 | Dim generator1 As ISourceGenerator = New CsvGenerator
61 |
62 | Dim iaGenerator = {generator1}.ToImmutableArray
63 | 'Dim iaGenerator = New ImmutableArray(Of ISourceGenerator) From {generator1}
64 |
65 | Dim additionalFiles As ImmutableArray(Of AdditionalText) = ImmutableArray.Create(Of AdditionalText)(New AnalyzerAdditionalFile("Assets\DarkModeColorDictionary.csv"), New AnalyzerAdditionalFile("Assets\LightModeColorDictionary.csv"))
66 | Dim driver = VisualBasicGeneratorDriver.Create(iaGenerator,
67 | additionalFiles,
68 | Nothing,
69 | Nothing)
70 |
71 | Dim outputCompilation As Compilation = Nothing
72 | Dim generateDiagnostics As ImmutableArray(Of Diagnostic) = Nothing
73 | driver.RunGeneratorsAndUpdateCompilation(compilation, outputCompilation, generateDiagnostics)
74 |
75 | Return (generateDiagnostics, $"{outputCompilation.SyntaxTrees(1)}{outputCompilation.SyntaxTrees(2)}")
76 |
77 | End Function
78 |
79 | End Module
80 |
--------------------------------------------------------------------------------
/TestConsoleApp/TestConsoleApp.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | TestConsoleApp
6 | netcoreapp3.1
7 | en-US
8 | 1.0.0.1
9 | 1.0.0.1
10 |
11 |
12 |
13 | all
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 |
16 |
17 | all
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Always
28 |
29 |
30 | Always
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/_global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "5.0.200-preview.21079.7",
4 | "allowPrerelease": true,
5 | "rollForward": "major"
6 | }
7 | }
--------------------------------------------------------------------------------
/csvGenerator/CsvGenerator.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/csvGenerator/InternalErrorException.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 |
4 | Friend NotInheritable Class InternalErrorException
5 | Inherits Exception
6 |
7 | Public Sub New(message As String)
8 | MyBase.New(message)
9 | End Sub
10 |
11 | Public Sub New(message As String, innerException As Exception)
12 | MyBase.New(message, innerException)
13 | End Sub
14 |
15 | ' default constructor
16 | Public Sub New()
17 | MyBase.New("Internal error in the Microsoft Visual Basic runtime.")
18 | End Sub
19 |
20 | End Class
21 |
--------------------------------------------------------------------------------
/csvGenerator/MalformedLineException.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 |
4 | Imports System.ComponentModel
5 | Imports System.Globalization
6 |
7 | '''
8 | ''' Indicates a line cannot be parsed into fields
9 | '''
10 | '''
11 |
12 | Public Class MalformedLineException
13 | Inherits Exception
14 |
15 | '''
16 | ''' Creates a new exception with no properties set
17 | '''
18 | '''
19 | Public Sub New()
20 | MyBase.New()
21 | End Sub
22 |
23 | '''
24 | ''' Creates a new exception, setting Message and LineNumber
25 | '''
26 | ''' The message for the exception
27 | ''' The number of the line that is malformed
28 | '''
29 | Public Sub New(message As String, lineNumber As Long)
30 | MyBase.New(message)
31 | _lineNumber = lineNumber
32 | End Sub
33 |
34 | '''
35 | ''' Creates a new exception, setting Message
36 | '''
37 | ''' The message for the exception
38 | '''
39 | Public Sub New(message As String)
40 | MyBase.New(message)
41 | End Sub
42 |
43 | '''
44 | ''' Creates a new exception, setting Message, LineNumber, and InnerException
45 | '''
46 | ''' The message for the exception
47 | ''' The number of the line that is malformed
48 | ''' The inner exception for the exception
49 | '''
50 | Public Sub New(message As String, lineNumber As Long, innerException As Exception)
51 | MyBase.New(message, innerException)
52 | _lineNumber = lineNumber
53 | End Sub
54 |
55 | '''
56 | ''' Creates a new exception, setting Message and InnerException
57 | '''
58 | ''' The message for the exception
59 | ''' The inner exception for the exception
60 | '''
61 | Public Sub New(message As String, innerException As Exception)
62 | MyBase.New(message, innerException)
63 | End Sub
64 |
65 | '''
66 | ''' Constructor used for serialization
67 | '''
68 | '''
69 | '''
70 | '''
71 |
72 | Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
73 | MyBase.New(info, context)
74 |
75 | If info IsNot Nothing Then ' Fix FxCop violation ValidateArgumentsOfPublicMethods.
76 | _lineNumber = info.GetInt32(LINE_NUMBER_PROPERTY)
77 | Else
78 | _lineNumber = -1
79 | End If
80 | End Sub
81 |
82 | '''
83 | ''' The number of the offending line
84 | '''
85 | ''' The line number
86 | '''
87 |
88 | Public Property LineNumber() As Long
89 | Get
90 | Return _lineNumber
91 | End Get
92 | Set(value As Long)
93 | _lineNumber = value
94 | End Set
95 | End Property
96 |
97 | '''
98 | ''' Supports serialization
99 | '''
100 | '''
101 | '''
102 | '''
103 |
104 | Public Overrides Sub GetObjectData(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
105 | If info IsNot Nothing Then ' Fix FxCop violation ValidateArgumentsOfPublicMethods.
106 | info.AddValue(LINE_NUMBER_PROPERTY, _lineNumber, GetType(Long))
107 | End If
108 |
109 | MyBase.GetObjectData(info, context)
110 | End Sub
111 |
112 | '''
113 | ''' Appends extra data to string so that it's available when the exception is caught as an Exception
114 | '''
115 | ''' The base ToString plus the Line Number
116 | '''
117 | Public Overrides Function ToString() As String
118 | Return MyBase.ToString() & " " & SR.Format(SR.TextFieldParser_MalformedExtraData, Me.LineNumber.ToString(CultureInfo.InvariantCulture))
119 | End Function
120 |
121 | ' Holds the line number
122 | Private _lineNumber As Long
123 |
124 | ' Name of property used for serialization
125 | ' ReSharper disable once InconsistentNaming
126 | Private Const LINE_NUMBER_PROPERTY As String = "LineNumber"
127 |
128 | End Class
129 |
--------------------------------------------------------------------------------
/csvGenerator/Resoures/Common/SR.vb:
--------------------------------------------------------------------------------
1 | ' Licensed to the .NET Foundation under one or more agreements.
2 | ' The .NET Foundation licenses this file to you under the MIT license.
3 | '
4 | ' This is a stand-in for the SR class used throughout FX.
5 | '
6 | ' ReSharper disable once CheckNamespace
7 | ' ReSharper disable once InconsistentNaming
8 | Partial Friend Class SR
9 | ' ReSharper disable InconsistentNaming
10 | Friend Const IO_FileNotFound_Path As String = "IO File Not Found Path"
11 | Friend Const IO_FilePathException As String = "IO File Path Exception"
12 | Friend Const IO_GetParentPathIsRoot_Path As String = "IO Get Parent Path Is Root Path"
13 | Friend Const TextFieldParser_BufferExceededMaxSize As String = "Text Field Parser Buffer Exceeded Max Size"
14 | Friend Const TextFieldParser_DelimiterNothing As String = "Text Field Parser Delimiter Nothing"
15 | Friend Const TextFieldParser_EndCharsInDelimiter As String = "Text Field Parser End Chars In Delimiter"
16 | Friend Const TextFieldParser_FieldWidthsMustPositive As String = "Text Field Parser Field Widths Must Positive"
17 | Friend Const TextFieldParser_FieldWidthsNothing As String = "Text Field Parser Field Widths Nothing"
18 | Friend Const TextFieldParser_IllegalDelimiter As String = "Text Field Parser Illegal Delimiter"
19 | Friend Const TextFieldParser_InvalidComment As String = "Text Field Parser Invalid Comment"
20 | Friend Const TextFieldParser_MalFormedDelimitedLine As String = "Text Field Parser MalFormed Delimited Line"
21 | Friend Const TextFieldParser_MalformedExtraData As String = "Text Field Parser Malformed Extra Data"
22 | Friend Const TextFieldParser_MalFormedFixedWidthLine As String = "Text Field Parser MalFormed Fixed Width Line"
23 | Friend Const TextFieldParser_MaxLineSizeExceeded As String = "Text Field Parser Max Line Size Exceeded"
24 | Friend Const TextFieldParser_NumberOfCharsMustBePositive As String = "Text Field Parser Number Of Chars Must Be Positive"
25 | Friend Const TextFieldParser_StreamNotReadable As String = "Text Field Parser Stream Not Readable"
26 | Friend Const TextFieldParser_WhitespaceInToken As String = "Text Field Parser Whitespace In Token"
27 | ' ReSharper restore InconsistentNaming
28 |
29 | Friend Shared Function Format(resourceFormat As String, p1 As Object) As String
30 | Return String.Format(resourceFormat, p1)
31 | End Function
32 |
33 | End Class
34 |
--------------------------------------------------------------------------------
/csvGenerator/csvGenerator.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CVS_Generator
5 | netstandard2.0
6 | true
7 | false
8 | On
9 | Text
10 | Off
11 | en-US
12 | 1.0.0.1
13 | 1.0.0.1
14 |
15 |
16 | 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036
17 |
18 |
19 | 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036
20 |
21 |
22 |
23 |
24 |
25 |
26 | all
27 | runtime; build; native; contentfiles; analyzers; buildtransitive
28 |
29 |
30 |
31 | all
32 | runtime; build; native; contentfiles; analyzers; buildtransitive
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------