Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions snippets/visualbasic/REORGANIZATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Visual Basic Snippet Reorganization

This document describes the reorganization of Visual Basic code snippets from the legacy `VS_Snippets_CLR` structure to a namespace-based organization that matches the C# snippet structure.

## Overview

Previously, VB snippets were organized under `snippets/visualbasic/VS_Snippets_CLR` with inconsistent naming patterns. They have been reorganized to match the C# snippet organization using namespace and API-based directory structures.

## Reorganization Pattern

### Before (Old Structure)
```
snippets/visualbasic/VS_Snippets_CLR/
├── directoryinforoot/VB/directoryinforoot2.vb
├── List`1_IndexOf/vb/source.vb
├── Generic.SortedDictionary/VB/source.vb
├── environment.FailFast/vb/ff.vb
└── stringbuilder.replace/VB/replace.vb
```

### After (New Structure)
```
snippets/visualbasic/
├── System.IO/DirectoryInfo/Root/directoryinforoot2.vb
├── System.Collections.Generic/ListT/IndexOf/source.vb
├── System.Collections.Generic/SortedDictionaryTKey,TValue/Overview/source.vb
├── System/Environment/FailFast/ff.vb
└── System.Text/StringBuilder/Replace/replace.vb
```

## Naming Conventions

### Namespace Mapping
- `VS_Snippets_CLR` files are mapped to appropriate namespaces:
- Files starting with `Generic.` → `System.Collections.Generic`
- Files with `directoryinfo`, `fileinfo`, `path` → `System.IO`
- Files with `environment`, `console`, `datetime`, `string`, `array`, `math` → `System`
- Files with `stringbuilder`, `regex` → `System.Text`
- Files with `thread` → `System.Threading`

### Type Name Mapping
- Generic type names are converted to match C# patterns:
- `List`1` → `ListT`
- `Dictionary`2` → `DictionaryTKey,TValue`
- `SortedDictionary`2` → `SortedDictionaryTKey,TValue`
- `SortedList`2` → `SortedListTKey,TValue`
- `Queue`1` → `QueueT`
- `Stack`1` → `StackT`

### Member/Method Mapping
- Constructor examples → `.ctor`
- Method-specific examples use the method name (e.g., `IndexOf`, `Contains`)
- General class examples → `Overview`

## Project Files

Each snippet directory includes a `Project.vbproj` file for compilation:

```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
```

## XML Reference Updates

All XML documentation files have been updated to reference the new snippet paths:

### Before
```xml
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/List`1_IndexOf/vb/source.vb" id="Snippet1":::
```

### After
```xml
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/ListT/IndexOf/source.vb" id="Snippet1":::
```

## Moved Snippets Summary

The following categories of snippets have been successfully reorganized:

### System.Collections.Generic (13 files)
- `ListT/IndexOf/` - List<T>.IndexOf examples
- `ListT/Ranges/` - List<T> range operations
- `QueueT/Overview/` - Queue<T> general examples
- `StackT/Overview/` - Stack<T> general examples
- `DictionaryTKey,TValue/.ctor/` - Dictionary constructors
- `SortedDictionaryTKey,TValue/Overview/` - SortedDictionary examples
- `SortedListTKey,TValue/IDictionary/` - SortedList as IDictionary
- `IDictionaryTKey,TValue/Overview/` - IDictionary interface examples

### System.IO (9 files)
- `DirectoryInfo/Root/` - DirectoryInfo.Root property
- `DirectoryInfo/GetDirectories/` - DirectoryInfo.GetDirectories method
- `DirectoryInfo/CreateSubdirectory/` - Directory creation
- `DirectoryInfo/Delete/` - Directory deletion
- `DirectoryInfo/MoveTo/` - Directory moving
- `DirectoryInfo/Parent/` - Parent directory access
- `FileInfo/IsReadOnly/` - FileInfo.IsReadOnly property
- `FileInfo/CopyTo/` - File copying
- `FileInfo/GetAccessControl/` - File access control
- `Path/Combine/` - Path.Combine method

### System (7 files)
- `Environment/FailFast/` - Environment.FailFast method
- `Console/KeyAvailable/` - Console.KeyAvailable property
- `Console/ReadKey/` - Console.ReadKey method
- `DateTime/DayOfWeek/` - DateTime.DayOfWeek property
- `Math/Max/` - Math.Max method
- `Math/Min/` - Math.Min method

### System.Collections (1 file)
- `ArrayList/Overview/` - ArrayList general examples

### System.Text (1 file)
- `StringBuilder/Replace/` - StringBuilder.Replace method

### System.Threading (2 files)
- `Thread/Sleep/` - Thread.Sleep method
- `Thread/Abort/` - Thread abortion examples

## Validation

All moved snippets:
1. ✅ Build successfully with their project files
2. ✅ Maintain their original snippet IDs and functionality
3. ✅ Have updated XML references in documentation files
4. ✅ Follow the established C# snippet organization pattern

## Benefits

1. **Consistency**: VB snippets now follow the same organization pattern as C# snippets
2. **Discoverability**: Easier to find snippets by namespace and API
3. **Maintainability**: Clearer structure for adding new snippets
4. **Build Validation**: Each snippet can be independently compiled and validated
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'<Snippet1>
Imports System.Collections.Generic

Public Class Example

Public Shared Sub Main()

' Create a new sorted dictionary of strings, with string
' keys and a case-insensitive comparer.
Dim openWith As New SortedDictionary(Of String, String)( _
StringComparer.CurrentCultureIgnoreCase)

' Add some elements to the sorted dictionary.
openWith.Add("txt", "notepad.exe")
openWith.Add("Bmp", "paint.exe")
openWith.Add("DIB", "paint.exe")
openWith.Add("rtf", "wordpad.exe")

' Create a Dictionary of strings with string keys and a
' case-insensitive equality comparer, and initialize it
' with the contents of the sorted dictionary.
Dim copy As New Dictionary(Of String, String)(openWith, _
StringComparer.CurrentCultureIgnoreCase)

' List the contents of the copy.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In copy
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp

End Sub

End Class

' This code example produces the following output:
'
'Key = Bmp, Value = paint.exe
'Key = DIB, Value = paint.exe
'Key = rtf, Value = wordpad.exe
'Key = txt, Value = notepad.exe
'</Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'<Snippet1>
Imports System.Collections.Generic

Public Class Example

Public Shared Sub Main()

' Create a new dictionary of strings, with string keys and
' an initial capacity of 4.
Dim openWith As New Dictionary(Of String, String)(4)

' Add 4 elements to the dictionary.
openWith.Add("txt", "notepad.exe")
openWith.Add("bmp", "paint.exe")
openWith.Add("dib", "paint.exe")
openWith.Add("rtf", "wordpad.exe")

' List the contents of the dictionary.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp

End Sub

End Class

' This code example produces the following output:
'
'Key = txt, Value = notepad.exe
'Key = bmp, Value = paint.exe
'Key = dib, Value = paint.exe
'Key = rtf, Value = wordpad.exe
'</Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Imports System.Collections.Generic

Public Class Example
Public Shared Sub Main()
' Create a new dictionary of strings, with string keys.
'
Dim exDictionary As New Dictionary(Of Integer, String)

' Add some elements to the dictionary. There are no
' duplicate keys, but some of the values are duplicates.
exDictionary.Add(0, "notepad.exe")
exDictionary.Add(1, "paint.exe")
exDictionary.Add(2, "paint.exe")
exDictionary.Add(3, "wordpad.exe")
Dim myDictionary As IDictionary(Of Integer, String) = exDictionary
' <Snippet11>
For Each kvp As KeyValuePair(Of Integer, String) In myDictionary
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value)
Next kvp
' </Snippet11>
End Sub
End Class

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
' <Snippet1>
Imports System.Collections.Generic

Public Class Example

Public Shared Sub Main()

Dim dinosaurs As New List(Of String)

dinosaurs.Add("Tyrannosaurus")
dinosaurs.Add("Amargasaurus")
dinosaurs.Add("Mamenchisaurus")
dinosaurs.Add("Brachiosaurus")
dinosaurs.Add("Deinonychus")
dinosaurs.Add("Tyrannosaurus")
dinosaurs.Add("Compsognathus")

Console.WriteLine()
For Each dinosaur As String In dinosaurs
Console.WriteLine(dinosaur)
Next

Console.WriteLine(vbLf & _
"IndexOf(""Tyrannosaurus""): {0}", _
dinosaurs.IndexOf("Tyrannosaurus"))

Console.WriteLine(vbLf & _
"IndexOf(""Tyrannosaurus"", 3): {0}", _
dinosaurs.IndexOf("Tyrannosaurus", 3))

Console.WriteLine(vbLf & _
"IndexOf(""Tyrannosaurus"", 2, 2): {0}", _
dinosaurs.IndexOf("Tyrannosaurus", 2, 2))

End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'IndexOf("Tyrannosaurus"): 0
'
'IndexOf("Tyrannosaurus", 3): 5
'
'IndexOf("Tyrannosaurus", 2, 2): -1
' </Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
Loading