Skip to content

Commit c5df7c6

Browse files
Copilotcsharpfritz
andcommitted
Add Visual Studio snippets package for BlazorWebFormsComponents
Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
1 parent 579659c commit c5df7c6

23 files changed

Lines changed: 844 additions & 0 deletions

BlazorMeetsWebForms.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionInfo", "SolutionInf
3838
EndProject
3939
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeforeWebForms", "samples\BeforeWebForms\BeforeWebForms.csproj", "{CA277C6F-A3DD-4FAF-9B7C-56E7B844CEF7}"
4040
EndProject
41+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
42+
EndProject
43+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWebFormsComponents.Snippets", "src\BlazorWebFormsComponents.Snippets\BlazorWebFormsComponents.Snippets.csproj", "{E4117E05-012C-45B5-B427-46A2D63ED2D1}"
44+
EndProject
4145
Global
4246
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4347
Debug|Any CPU = Debug|Any CPU
@@ -155,6 +159,24 @@ Global
155159
{CA277C6F-A3DD-4FAF-9B7C-56E7B844CEF7}.WebForms|x64.Build.0 = WebForms|Any CPU
156160
{CA277C6F-A3DD-4FAF-9B7C-56E7B844CEF7}.WebForms|x86.ActiveCfg = WebForms|Any CPU
157161
{CA277C6F-A3DD-4FAF-9B7C-56E7B844CEF7}.WebForms|x86.Build.0 = WebForms|Any CPU
162+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
163+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
164+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Debug|x64.ActiveCfg = Debug|Any CPU
165+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Debug|x64.Build.0 = Debug|Any CPU
166+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Debug|x86.ActiveCfg = Debug|Any CPU
167+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Debug|x86.Build.0 = Debug|Any CPU
168+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
169+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Release|Any CPU.Build.0 = Release|Any CPU
170+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Release|x64.ActiveCfg = Release|Any CPU
171+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Release|x64.Build.0 = Release|Any CPU
172+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Release|x86.ActiveCfg = Release|Any CPU
173+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.Release|x86.Build.0 = Release|Any CPU
174+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.WebForms|Any CPU.ActiveCfg = Debug|Any CPU
175+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.WebForms|Any CPU.Build.0 = Debug|Any CPU
176+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.WebForms|x64.ActiveCfg = Debug|Any CPU
177+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.WebForms|x64.Build.0 = Debug|Any CPU
178+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.WebForms|x86.ActiveCfg = Debug|Any CPU
179+
{E4117E05-012C-45B5-B427-46A2D63ED2D1}.WebForms|x86.Build.0 = Debug|Any CPU
158180
EndGlobalSection
159181
GlobalSection(SolutionProperties) = preSolution
160182
HideSolutionNode = FALSE
@@ -165,6 +187,7 @@ Global
165187
{7218D3E2-38BD-429D-9D84-15E688BDC4A1} = {240E45D9-B9FF-42E8-B0C1-332861E02DBF}
166188
{1669CD22-5CCE-4D96-A02B-31D81B5EFB2B} = {240E45D9-B9FF-42E8-B0C1-332861E02DBF}
167189
{CA277C6F-A3DD-4FAF-9B7C-56E7B844CEF7} = {240E45D9-B9FF-42E8-B0C1-332861E02DBF}
190+
{E4117E05-012C-45B5-B427-46A2D63ED2D1} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
168191
EndGlobalSection
169192
GlobalSection(ExtensibilityGlobals) = postSolution
170193
SolutionGuid = {E288F9FB-039F-4718-8AEB-85F89B29EB4E}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ There are a handful of features that augment the ASP<span></span>.NET developmen
8989

9090
- [DataBinder](docs/UtilityFeatures/Databinder.md)
9191
- [JavaScript Setup](docs/UtilityFeatures/JavaScriptSetup.md) - Options for auto-loading required JavaScript
92+
- [Snippets Package](docs/UtilityFeatures/Snippets.md) - Visual Studio code snippets for static imports and component patterns
9293
- [ViewState](docs/UtilityFeatures/ViewState.md)
9394

9495
## Compiling the project

docs/UtilityFeatures/Snippets.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Code Snippets Package
2+
3+
The BlazorWebFormsComponents Snippets package provides Visual Studio code snippets to accelerate development with the BlazorWebFormsComponents library.
4+
5+
## Overview
6+
7+
This Visual Studio extension includes snippets for:
8+
9+
1. **Static Imports** - Quickly add `@using static` directives for enumeration types
10+
2. **Component Patterns** - Common component markup templates with placeholders
11+
3. **Validation Controls** - Quick templates for validation scenarios
12+
13+
## Installation
14+
15+
### From VSIX File
16+
17+
1. Download the `.vsix` file from the [releases page](https://github.com/FritzAndFriends/BlazorWebFormsComponents/releases)
18+
2. Double-click the `.vsix` file to install
19+
3. Restart Visual Studio
20+
21+
### From Visual Studio Marketplace
22+
23+
1. Open Visual Studio
24+
2. Go to **Extensions** > **Manage Extensions**
25+
3. Search for "Blazor Web Forms Components Snippets"
26+
4. Click **Download** and restart Visual Studio
27+
28+
## Building the Extension
29+
30+
To build the VSIX extension from source:
31+
32+
```bash
33+
cd src/BlazorWebFormsComponents.Snippets
34+
dotnet build
35+
```
36+
37+
The VSIX file will be created in `bin/Debug/net472/` or `bin/Release/net472/`.
38+
39+
## Available Snippets
40+
41+
### Static Import Snippets
42+
43+
| Shortcut | Description | Output |
44+
|----------|-------------|--------|
45+
| `bwfall` | All common static imports | All enumeration static imports |
46+
| `bwfrepeat` | RepeatLayout enumeration | `@using static BlazorWebFormsComponents.Enums.RepeatLayout` |
47+
| `bwfdatalist` | DataListEnum enumeration | `@using static BlazorWebFormsComponents.Enums.DataListEnum` |
48+
| `bwfvalidation` | Validation enumerations | Static imports for validation types |
49+
50+
### Component Snippets
51+
52+
| Shortcut | Component | Description |
53+
|----------|-----------|-------------|
54+
| `bwfgridview` | GridView | Basic GridView with columns |
55+
| `bwfdl` | DataList | DataList with ItemTemplate |
56+
| `bwfrepeater` | Repeater | Repeater with ItemTemplate |
57+
| `bwfformview` | FormView | FormView with Item and Edit templates |
58+
| `bwfbutton` | Button | Button with click handler |
59+
| `bwftextbox` | TextBox | TextBox with binding |
60+
| `bwfcheckboxlist` | CheckBoxList | CheckBoxList with data binding |
61+
62+
### Validation Snippets
63+
64+
| Shortcut | Control | Description |
65+
|----------|---------|-------------|
66+
| `bwfrequired` | RequiredFieldValidator | Required field validation |
67+
| `bwfvalsummary` | ValidationSummary | Validation summary display |
68+
69+
## Usage Examples
70+
71+
### Example 1: Adding Static Imports
72+
73+
To use enumeration values without full qualification:
74+
75+
1. Type `bwfall` at the top of your `.razor` file
76+
2. Press `Tab` twice
77+
3. All common static imports are added
78+
79+
```razor
80+
@using BlazorWebFormsComponents
81+
@using static BlazorWebFormsComponents.Enums.RepeatLayout
82+
@using static BlazorWebFormsComponents.Enums.DataListEnum
83+
@using static BlazorWebFormsComponents.Enums.ValidationSummaryDisplayMode
84+
@using static BlazorWebFormsComponents.Enums.ButtonType
85+
@using static BlazorWebFormsComponents.Enums.ValidationDataType
86+
@using static BlazorWebFormsComponents.Enums.ValidationCompareOperator
87+
@using static BlazorWebFormsComponents.Enums.BorderStyle
88+
@using static BlazorWebFormsComponents.Enums.HorizontalAlign
89+
@using static BlazorWebFormsComponents.Enums.VerticalAlign
90+
@using static BlazorWebFormsComponents.Enums.TextAlign
91+
```
92+
93+
Now you can use values like `Table`, `Flow`, `Horizontal`, `Vertical` directly:
94+
95+
```razor
96+
<DataList TItemType="Product" DataSource="@products" RepeatLayout="Table" RepeatDirection="Horizontal">
97+
...
98+
</DataList>
99+
```
100+
101+
### Example 2: Creating a GridView
102+
103+
1. Type `bwfgridview` where you want the component
104+
2. Press `Tab` twice
105+
3. Fill in the placeholders:
106+
- First tab stop: Item type (e.g., `Product`)
107+
- Second tab stop: Data source variable (e.g., `products`)
108+
4. Add more columns as needed
109+
110+
### Example 3: Adding Form Validation
111+
112+
1. Type `bwftextbox` to create a TextBox
113+
2. Type `bwfrequired` to add validation
114+
3. Type `bwfvalsummary` to add a validation summary
115+
116+
```razor
117+
<TextBox @bind-Text="userName" CssClass="form-control" />
118+
<RequiredFieldValidator ControlToValidate="userName"
119+
ErrorMessage="User name is required"
120+
Display="Dynamic" />
121+
122+
<ValidationSummary HeaderText="Please correct the following errors:"
123+
DisplayMode="BulletList"
124+
ShowSummary="true" />
125+
```
126+
127+
## Why Use Static Imports?
128+
129+
BlazorWebFormsComponents uses static classes for enumeration types to provide a more object-oriented approach. Static imports allow you to use these values more concisely:
130+
131+
**Without static import:**
132+
```razor
133+
<DataList RepeatLayout="BlazorWebFormsComponents.Enums.RepeatLayout.Table" />
134+
```
135+
136+
**With static import:**
137+
```razor
138+
@using static BlazorWebFormsComponents.Enums.RepeatLayout
139+
140+
<DataList RepeatLayout="Table" />
141+
```
142+
143+
## Supported Languages
144+
145+
The snippets are available in:
146+
- Razor (`.razor` files)
147+
- C# (`.cs` files, for the static imports)
148+
- HTML (for component markup)
149+
150+
## Requirements
151+
152+
- Visual Studio 2022 or later
153+
- BlazorWebFormsComponents NuGet package in your project
154+
155+
## Contributing
156+
157+
To add new snippets:
158+
159+
1. Create a new `.snippet` file in the `Snippets/` folder
160+
2. Follow the XML structure of existing snippets
161+
3. Add appropriate shortcut, description, and code template
162+
4. Build the project to test
163+
164+
## Structure
165+
166+
```
167+
BlazorWebFormsComponents.Snippets/
168+
├── BlazorWebFormsComponents.Snippets.csproj # Project file
169+
├── source.extension.vsixmanifest # VSIX manifest
170+
├── LICENSE.txt # MIT license
171+
├── icon.png # Extension icon
172+
├── README.md # Documentation
173+
└── Snippets/ # Snippet files
174+
├── snippets.pkgdef # VS registration
175+
├── AllStaticImports.snippet
176+
├── StaticImportRepeatLayout.snippet
177+
├── StaticImportDataListEnum.snippet
178+
├── StaticImportValidation.snippet
179+
├── GridViewComponent.snippet
180+
├── DataListComponent.snippet
181+
├── RepeaterComponent.snippet
182+
├── FormViewComponent.snippet
183+
├── ButtonComponent.snippet
184+
├── TextBoxComponent.snippet
185+
├── CheckBoxListComponent.snippet
186+
├── RequiredFieldValidator.snippet
187+
└── ValidationSummary.snippet
188+
```
189+
190+
## More Information
191+
192+
- [BlazorWebFormsComponents Documentation](https://fritzandfriends.github.io/BlazorWebFormsComponents/)
193+
- [GitHub Repository](https://github.com/FritzAndFriends/BlazorWebFormsComponents)
194+
- [NuGet Package](https://www.nuget.org/packages/Fritz.BlazorWebFormsComponents/)
195+
- [Visual Studio Snippets Reference](https://learn.microsoft.com/en-us/visualstudio/ide/code-snippets)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ nav:
104104
- Utility Features:
105105
- Databinder: UtilityFeatures/Databinder.md
106106
- JavaScript Setup: UtilityFeatures/JavaScriptSetup.md
107+
- Snippets Package: UtilityFeatures/Snippets.md
107108
- ViewState: UtilityFeatures/ViewState.md
108109
- Migration:
109110
- Getting started: Migration/readme.md
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net472</TargetFramework>
5+
<GeneratePkgDefFile>true</GeneratePkgDefFile>
6+
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer>
7+
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
8+
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
9+
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
10+
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
11+
</PropertyGroup>
12+
13+
<PropertyGroup>
14+
<StartAction>Program</StartAction>
15+
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
16+
<StartArguments>/rootsuffix Exp</StartArguments>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.12.2172">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Content Include="Snippets\**\*.snippet">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
<IncludeInVSIX>true</IncludeInVSIX>
30+
</Content>
31+
<Content Include="Snippets\snippets.pkgdef">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
<IncludeInVSIX>true</IncludeInVSIX>
34+
</Content>
35+
<Content Include="LICENSE.txt">
36+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
37+
<IncludeInVSIX>true</IncludeInVSIX>
38+
</Content>
39+
<Content Include="icon.png">
40+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41+
<IncludeInVSIX>true</IncludeInVSIX>
42+
</Content>
43+
<Content Include="README.md">
44+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
45+
<IncludeInVSIX>false</IncludeInVSIX>
46+
</Content>
47+
</ItemGroup>
48+
49+
<ItemGroup>
50+
<None Include="source.extension.vsixmanifest">
51+
<SubType>Designer</SubType>
52+
</None>
53+
</ItemGroup>
54+
55+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Fritz and Friends
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)