Skip to main content

SG4MVC by Mark Flanagan

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: SG4MVC

Runtime helpers used by code generated by Sg4Mvc.Generator

Author: Mark Flanagan

NuGet: https://www.nuget.org/packages/SG4MVC/

You can find more details at https://github.com/SG4MVC/SG4MVC

Source: https://github.com/SG4MVC/SG4MVC

Author

note

Mark Flanagan Alt text

Original Readme

note

Nuget (with prereleases)

SG4MVC

SG4MVC is a source generator for ASP.NET MVC Core apps that creates strongly typed helpers that eliminate the use of literal strings in many places.

It is a re-implementation of R4MVC using source generators.

R4MVC runs as you build, and currently has only been tested on net6.0

Get Started?

Just want to get started? Visit the Get Started page for installation and configuration instructions.

Benefits

Instead of

@Html.ActionLink("Dinner Details", "Details", "Dinners", new \{ id = Model.DinnerID }, null)

SG4MVC lets you write

@Html.ActionLink("Dinner Details", MVC.Dinners.Details(Model.DinnerID))

When you're using tag helpers, instead of

<a asp-action="Details" asp-controller="Dinners" asp-route-id="@Model.DinnerID">Dinner Details</a>

you can write (after registering Sg4Mvc tag helpers in _ViewImports.cshtml with the directive: @addTagHelper *, Sg4Mvc)

<a mvc-action="MVC.Dinners.Details(Model.DinnerID)">Dinner Details</a>

and that's just the beginning!

About

note

Generate strong typed HTML helpers for ASP.NET MVC projects.

How to use

Example (source csproj, source files)

This is the CSharp Project that references SG4MVC

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SG4MVC" Version="0.9.4-beta" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="Sg4Mvc.GenerateSg4Mvc" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated />
// This file was generated by SG4MVC.

// Make sure the compiler doesn't complain about missing Xml comments and CLS compliance
// 0108: suppress "Foo hides inherited member Foo.Use the new keyword if hiding was intended." when a controller and its abstract parent are both processed
#pragma warning disable 1591, 3008, 3009, 0108, CS8981
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Routing;
using Sg4Mvc.ActionResults;
using Sg4Mvc;

[GeneratedCode("Sg4Mvc", "1.0"), DebuggerNonUserCode]
public static partial class MVC
{
public static readonly MVCDemo.Controllers.HomeController Home = new MVCDemo.Controllers.Sg4Mvc_HomeController();
public static readonly Sg4Mvc.SharedController Shared = new Sg4Mvc.SharedController();
}
#pragma warning restore 1591, 3008, 3009, 0108, CS8981

Useful

Download Example (.NET C#)

Share SG4MVC

https://ignatandrei.github.io/RSCG_Examples/v2/docs/SG4MVC

aaa

Category "MVC" has the following generators:

1 SG4MVC

See category

MVC