Woody230.BindableEnum
3.0.0
dotnet add package Woody230.BindableEnum --version 3.0.0
NuGet\Install-Package Woody230.BindableEnum -Version 3.0.0
<PackageReference Include="Woody230.BindableEnum" Version="3.0.0" />
<PackageVersion Include="Woody230.BindableEnum" Version="3.0.0" />
<PackageReference Include="Woody230.BindableEnum" />
paket add Woody230.BindableEnum --version 3.0.0
#r "nuget: Woody230.BindableEnum, 3.0.0"
#:package Woody230.BindableEnum@3.0.0
#addin nuget:?package=Woody230.BindableEnum&version=3.0.0
#tool nuget:?package=Woody230.BindableEnum&version=3.0.0
BindableEnum
Provides an enumeration wrapper that holds whether binding from the original string is successful.
This is useful when automatic model state validation needs to be disabled so that validation can be postponed to a later point in time.
Normally a bad enum will cause the binding to fail, even though it would be preferrable to check for this in the postponed validation.
With the bindable enum this is avoided, while also providing the convenience of automatically handling the conversion to an enum that would otherwise be missing when reverting back to using a string within a model.
Setup
Program.cs
Configure the BindableEnumSwaggerGenOptions on the service collection.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Woody230.BindableEnum.Options;
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureOptions<BindableEnumSwaggerGenOptions>();
This will map the BindableEnum generic type definition with an OpenApiSchema type of string.
Also, the BindableEnumSchemaFilter is applied in order to add the enumerations to the OpenApiSchema.
Model
When declaring your bindable enumeration, you can use the BindedEnumAttribute to validate that the enumeration has been successfully binded.
Note that a null bindable enumeration is NOT validated. The RequiredAttribute must be added to support this.
using System.ComponentModel.DataAnnotations;
using Woody230.BindableEnum.Attributes;
using Woody230.BindableEnum.Models;
public record WeatherForecast
{
[Required]
[BindedEnum]
public IBindableEnum<DayOfWeek> DayOfWeek { get; set; }
}
Extensions
If you are using the interface IBindableEnum{T}, you can use the Bindable() extension method to convert an enumeration into a IBindableEnum{T}.
using System;
using Woody230.BindableEnum.Models;
IBindableEnum<DayOfWeek> dayOfWeek = DayOfWeek.Sunday.Bindable();
If you are using the implementation BindableEnum{T}, then there is an implicit conversion between the enumeration and the BindableEnum{T} in both directions.
using System;
using Woody230.BindableEnum.Models;
BindableEnum<DayOfWeek> dayOfWeek = DayOfWeek.Sunday;
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Woody230.BindableEnum:
| Package | Downloads |
|---|---|
|
Woody230.BindableEnum.FluentValidation
Extensions for the FluentValidations library within the context of the BindableEnum library. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 117 | 3/8/2026 |
| 2.7.0 | 289 | 12/15/2025 |
| 2.6.0 | 238 | 6/22/2025 |
| 2.5.0 | 226 | 6/22/2025 |
| 2.2.0 | 317 | 6/13/2025 |
| 2.1.1 | 268 | 9/27/2024 |
| 2.1.0 | 280 | 4/8/2024 |
| 2.0.0 | 256 | 3/28/2024 |
| 1.4.1 | 248 | 10/27/2023 |
| 1.4.0 | 253 | 7/10/2023 |
| 1.3.0 | 446 | 4/24/2023 |
| 1.2.3 | 288 | 4/24/2023 |
| 1.2.2 | 297 | 4/24/2023 |
| 1.2.1 | 303 | 4/24/2023 |
| 1.2.0 | 289 | 4/23/2023 |
| 1.1.2 | 312 | 4/22/2023 |
Update assembly name to match namespace.