EngstromJimmy / Blazm.Extension

A Visual Studio Extension that solves some of the pain points when working with Blazor
MIT License
62 stars 6 forks source link

Include useful Blazor snippets #19

Open Herdo opened 3 weeks ago

Herdo commented 3 weeks ago

I think the Blazm extension might be the right place to use some common code snippets for Blazor, as this extension already bundles some other amazing features!

Visual Studio supports distributing code snippets with extensions: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-distribute-code-snippets

Some suggested snippets that come to my mind, which could be included with this extension:

// propInjectBlazor
[Inject]
public IService Service { get; set; } = default!;

// propParamBlazor
[Parameter]
public T Parameter { get; set; }

// propParamRequiredBlazor
[Parameter, EditorRequired]
public T Parameter { get; set; }

Snippet codes could end with Blazm as well, and there's probably a ton more to add from other peoples experience.

EngstromJimmy commented 3 weeks ago

I have played around with this idea. Happy more people want it :)

Herdo commented 3 weeks ago

I've played around with it for a little bit and got it working for the most part. I've encountered a "major" issue, though, which seems to be known by Microsoft, but is not on the roadmap to be implemented: Snippets in the Razor editor are barebone. They do not support:

Function, Declarations, Id, Import(s), Keyword(s), Literal, Namespace, Object, Reference(s), or Command https://github.com/dotnet/razor/pull/9327#issue-1914492231

The snippets work as expected in normal C# files, though. You can have a look at the attached code. BlazorSnippets.zip

P.S.: Required using statements could be triggered as well, but most likely they are already in place through GlobalUsings.cs.