BlazorMarkupBeautify 1.0.1
dotnet add package BlazorMarkupBeautify --version 1.0.1
NuGet\Install-Package BlazorMarkupBeautify -Version 1.0.1
<PackageReference Include="BlazorMarkupBeautify" Version="1.0.1" />
paket add BlazorMarkupBeautify --version 1.0.1
#r "nuget: BlazorMarkupBeautify, 1.0.1"
// Install BlazorMarkupBeautify as a Cake Addin #addin nuget:?package=BlazorMarkupBeautify&version=1.0.1 // Install BlazorMarkupBeautify as a Cake Tool #tool nuget:?package=BlazorMarkupBeautify&version=1.0.1
BlazorMarkupBeautify
BlazorMarkupBeautify is a .NET library intended to enable developers use control structures through markup instead of conspicuous C# code in their Blazor applications.
Purpose
The purpose of this library is to enable developers use markup instead of C# when using control structures. This should help increase readability of the code, instead of having to switch between html and C#.
Currently, this library supports conditional and iteration.
Installation
Install this package through NuGet Packages in Visual Studio or through command line. Alternatively, you can download the latest release here.
Tip: Since you most likely will be using this on all your Razor pages, you can include this line in "_Imports.razor"
@using BlazorMarkupBeautify
Conditionals
Conditional statements are used to execute one or more statements if a condition is met.
An example in current Blazor can be seen below:
@if (condition)
{
<p>Condition evaluated to true.</p>
}
else
{
<p>Condition evaluated to false.</p>
}
This mixes both C# and HTML, which may be confusing to the reader.
Instead, using this library, the code can be rewritten with almost purely HTML as seen in the example below:
<Conditional Condition=@condition>
<True>
<p>Condition evaluated to true.</p>
</True>
<False>
<p>Condition evaluated to false.</p>
</False>
</Conditional>
Iteration
Iteration serves the purpose of repeating a statement a certain number of times.
An example in current Blazor can be seen below:
@foreach(var number in @Enumerable.Range(0, 10))
{
<p>@number</p>
}
Instead, using this library, the code can be rewritten with almost purely HTML as seen in the example below:
<ForEach Collection=@Enumerable.Range(0, 10)>
<p>@context</p>
</ForEach>
Fizz Buzz
To show a more complex example, below is a naive implementation of Fizz Buzz using this library:
<ForEach Collection=@Enumerable.Range(1, 100)>
<p>
<Conditional Condition=@(context % 3 == 0)>
<True>Fizz</True>
</Conditional>
<Conditional Condition=@(context % 5 == 0)>
<True>Buzz</True>
</Conditional>
<Conditional Condition=@(context % 3 != 0 && context % 5 != 0)>
<True>@context</True>
</Conditional>
</p>
</ForEach>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.