Fenris.OneOfContrib.Blazor 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Fenris.OneOfContrib.Blazor --version 1.0.4                
NuGet\Install-Package Fenris.OneOfContrib.Blazor -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fenris.OneOfContrib.Blazor" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fenris.OneOfContrib.Blazor --version 1.0.4                
#r "nuget: Fenris.OneOfContrib.Blazor, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Fenris.OneOfContrib.Blazor as a Cake Addin
#addin nuget:?package=Fenris.OneOfContrib.Blazor&version=1.0.4

// Install Fenris.OneOfContrib.Blazor as a Cake Tool
#tool nuget:?package=Fenris.OneOfContrib.Blazor&version=1.0.4                

Fenris.OneOfContrib.Blazor

A collection of Blazor components for working with OneOf types in your Blazor project.

🤔 Why?

I was working on a project where I needed to render different components based on the value of a OneOf. I couldn't get the OneOf.Switch() method to work in Blazor, and writing switch statements over and over again was annoying and looked messy.

Instead I made a component library, which is actually just a switch statement in disguise, and found it made my Blazor components much more readable and in general nicer to work with.

⭐ Features

  • Blazor components for OneOf types with up to 8 type parameters.
  • Blazor components for types that inherit from OneOfBase, also with up to 8 type parameters.

That's it. It's a pretty simple library 😁

💿 Installation

Install the Fenris.OneOfContrib.Blazor NuGet package.

dotnet add package Fenris.OneOfContrib.Blazor

🚀 Usage

See the Examples project for a full, simple example.

Let's make a small example where we have to deal with a OneOf<string, int>.

First, add the using either to your _Imports.razor file, or directly in your specific pages/components:

@using Fenris.OneOfContrib.Blazor.Components

Then use the component in your blazor pages or components

<OneOfSwitch2 Value="myOneOf">
    <T0Template>
        <p>It's a string and the value is @context!</p>
    </T0Template>
    <T1Template>
        <p>It's an int and the value is @context!</p>
    </T1Template>
</OneOfSwitch2>

@code {
    private OneOf<string, int> myOneOf = "Hello World!";
}

If you are using a OneOfBase type, you need to use the <OneOfBaseSwitch2> component instead. Everything else is identical.

If your union contains more than two types, you need to use the <OneOfSwitchN> or <OneOfBaseSwitchN> components, where N is the number of types in your union. E.g. <OneOfSwitch5>

🐛 Bugs, feature requests, and contributions

If you find a bug or have a feature request, please open an issue.

Pull requests are also welcome 😊

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.7 31 7/12/2024
1.0.7-alpha.36 23 7/12/2024
1.0.7-alpha.35 21 7/12/2024
1.0.6-rc.6 23 7/12/2024
1.0.6-alpha.29 22 7/12/2024
1.0.6-alpha.28 18 7/12/2024
1.0.6-alpha.27 25 7/11/2024
1.0.6-alpha.26 18 7/11/2024
1.0.6-alpha.25 21 7/11/2024
1.0.5 30 7/11/2024
1.0.5-rc 21 7/11/2024
1.0.5-alpha.24 28 7/11/2024
1.0.5-alpha.23 23 7/11/2024
1.0.5-alpha.22 20 7/11/2024
1.0.5-alpha.21 16 7/11/2024
1.0.5-alpha.20 20 7/11/2024
1.0.5-alpha.19 20 7/11/2024
1.0.4 124 1/26/2024
1.0.4-rc 64 1/26/2024
1.0.3-rc 76 1/26/2024
0.1.16-alpha 25 7/11/2024
0.1.15-alpha 24 7/11/2024
0.1.14-alpha 25 7/11/2024
0.1.13-alpha 30 7/11/2024
0.1.12-alpha 64 1/26/2024
0.1.11-alpha 62 1/26/2024