Fluxera.Enumeration.SystemTextJson
6.0.3
Prefix Reserved
See the version list below for details.
dotnet add package Fluxera.Enumeration.SystemTextJson --version 6.0.3
NuGet\Install-Package Fluxera.Enumeration.SystemTextJson -Version 6.0.3
<PackageReference Include="Fluxera.Enumeration.SystemTextJson" Version="6.0.3" />
paket add Fluxera.Enumeration.SystemTextJson --version 6.0.3
#r "nuget: Fluxera.Enumeration.SystemTextJson, 6.0.3"
// Install Fluxera.Enumeration.SystemTextJson as a Cake Addin #addin nuget:?package=Fluxera.Enumeration.SystemTextJson&version=6.0.3 // Install Fluxera.Enumeration.SystemTextJson as a Cake Tool #tool nuget:?package=Fluxera.Enumeration.SystemTextJson&version=6.0.3
Fluxera.Enumeration
An object-oriented enumeration library.
Usage
Define an enumerable as C# class that inherits from the Enumeration<TEnum>
base class.
Add the enumeration options as public static readonly fields to the new enumerable class.
public sealed class Color : Enumeration<Color>
{
public static readonly Color Red = new Color(0, "FF0000");
public static readonly Color Green = new Color(1, "00FF00");
public static readonly Color Blue = new Color(2, "0000FF");
public static readonly Color White = new Color(3, "FFFFFF");
public static readonly Color Black = new Color(4, "000000");
/// <inheritdoc />
private Color(int value, string hexValue, [CallerMemberName] string name = null!)
: base(value, name)
{
this.HexValue = hexValue;
}
public string HexValue { get; }
}
public class MessageType : Enumeration<MessageType>
{
public static readonly MessageType Email = new EmailType();
public static readonly MessageType Postal = new PostalType();
public static readonly MessageType TextMessage = new TextMessageType();
/// <inheritdoc />
private MessageType(int value, string name)
: base(value, name)
{
}
private sealed class EmailType : MessageType
{
/// <inheritdoc />
public EmailType() : base(0, "Email")
{
}
}
private sealed class PostalType : MessageType
{
/// <inheritdoc />
public PostalType() : base(1, "Postal")
{
}
}
private sealed class TextMessageType : MessageType
{
/// <inheritdoc />
public TextMessageType() : base(2, "TextMessage")
{
}
}
}
public abstract class Animal : Enumeration<Animal>
{
/// <inheritdoc />
protected Animal(int value, string name)
: base(value, name)
{
}
}
public sealed class Mammal : Animal
{
public static readonly Mammal Tiger = new Mammal(0);
public static readonly Mammal Elephant = new Mammal(1);
/// <inheritdoc />
private Mammal(int value, [CallerMemberName] string name = null!)
: base(value, name)
{
}
}
public sealed class Reptile : Animal
{
public static readonly Reptile Iguana = new Reptile(2);
public static readonly Reptile Python = new Reptile(3);
/// <inheritdoc />
private Reptile(int value, [CallerMemberName] string name = null!)
: base(value, name)
{
}
}
The Enumeration<TEnum>
provides a fluent API to configure switch-case like structures
to simplify the execution of action for specific cases.
public void PrintColorInfo(Color color)
{
color
.When(Color.Red).Then(() => SetConsoleColor(ConsoleColor.Red))
.When(Color.Blue).Then(() => SetConsoleColor(ConsoleColor.Blue))
.When(Color.Green).Then(() => SetConsoleColor(ConsoleColor.Green))
.Default(() => SetConsoleColor(ConsoleColor.White));
Console.WriteLine($"{color}({color.Value}) => #{color.HexValue}");
}
Future
We plan to implement support for OData server- and client-side to enable queries on Enumeration
like is was an simple C# enum
.
An Enumeration
should generate an EdmEnumType
in the metadata for an OData feed.
The simple way would be to add the enumeraions as complex type, but that feels wrong because
the object-oriented enumeration should work like an enum
and the EDM model would not
reflect the available options.
EdmEnumType color = new EdmEnumType("Default", "Color");
color.AddMember(new EdmEnumMember(color, "Red", new EdmIntegerConstant(0)));
color.AddMember(new EdmEnumMember(color, "Blue", new EdmIntegerConstant(1)));
color.AddMember(new EdmEnumMember(color, "Green", new EdmIntegerConstant(2)));
model.AddElement(color);
This cannot be achieved using the model builder because the enum methods are tightly bound to C# enum
.
<EnumType Name="Color">
<Member Name="Red" Value="0" />
<Member Name="Blue" Value="1" />
<Member Name="Green" Value="2" />
</EnumType>
We want to support filter queries like so:
https://localhost:5001/odata/Cars?$filter=Color eq 'Blue'
https://localhost:5001/odata/Cars?$filter=Color eq 1
https://github.com/OData/WebApi/issues/1186 https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/UnqualifiedCallAndEnumPrefixFreeResolver.cs
We also plan to support Swagger documentation in ASP.NET Core applications.
References
This library was inspired by:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Fluxera.Enumeration (>= 6.0.3)
- Fluxera.Guards (>= 6.0.5)
- JetBrains.Annotations (>= 2021.3.0)
- System.Text.Json (>= 6.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Fluxera.Enumeration.SystemTextJson:
Package | Downloads |
---|---|
Fluxera.Extensions.Hosting.Modules.AspNetCore
A module that enables ASP.NET Core. |
|
Fluxera.Extensions.Hosting.Modules.Messaging
A module that enables messaging based on MassTransit. |
|
Fluxera.Extensions.Hosting.Modules.HttpClient
A module that enables HTTP client services. |
|
Fluxera.Queries.AspNetCore
An OData v4 query parser and runtime for ASP.NET Core controllers and minimal APIs. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.2.4 | 383 | 11/1/2024 |
8.2.3 | 96 | 7/9/2024 |
8.2.2 | 1,157 | 6/15/2024 |
8.2.1 | 94 | 6/12/2024 |
8.2.0 | 97 | 6/12/2024 |
8.1.1 | 504 | 6/2/2024 |
8.1.0 | 554 | 5/26/2024 |
8.0.8 | 124 | 5/24/2024 |
8.0.7 | 95 | 5/24/2024 |
8.0.6 | 5,669 | 4/13/2024 |
8.0.5 | 163 | 4/13/2024 |
8.0.4 | 666 | 3/19/2024 |
8.0.3 | 1,951 | 2/22/2024 |
8.0.2 | 4,839 | 1/4/2024 |
8.0.1 | 851 | 11/23/2023 |
8.0.0 | 1,088 | 11/15/2023 |
7.1.6 | 787 | 7/23/2023 |
7.1.5 | 213 | 7/20/2023 |
7.1.4 | 713 | 6/21/2023 |
7.1.3 | 3,478 | 4/13/2023 |
7.1.2 | 932 | 3/16/2023 |
7.1.1 | 1,477 | 2/24/2023 |
7.1.0 | 2,104 | 1/18/2023 |
7.0.7 | 2,724 | 12/22/2022 |
7.0.6 | 321 | 12/13/2022 |
7.0.5 | 923 | 12/13/2022 |
7.0.4 | 1,420 | 12/9/2022 |
7.0.3 | 364 | 11/15/2022 |
7.0.2 | 335 | 11/12/2022 |
7.0.0 | 340 | 11/9/2022 |
6.1.6 | 3,221 | 10/12/2022 |
6.1.5 | 13,916 | 9/15/2022 |
6.1.4 | 2,399 | 7/30/2022 |
6.1.3 | 2,394 | 6/30/2022 |
6.1.2 | 2,419 | 6/15/2022 |
6.1.1 | 2,492 | 6/7/2022 |
6.1.0 | 448 | 6/1/2022 |
6.0.13 | 442 | 5/28/2022 |
6.0.12 | 461 | 5/5/2022 |
6.0.11 | 467 | 4/20/2022 |
6.0.10 | 443 | 3/26/2022 |
6.0.9 | 447 | 3/24/2022 |
6.0.8 | 461 | 2/17/2022 |
6.0.7 | 354 | 12/17/2021 |
6.0.6 | 545 | 12/11/2021 |
6.0.3 | 336 | 12/9/2021 |