Redpoint.StringEnum 2025.1002.636

Prefix Reserved
dotnet add package Redpoint.StringEnum --version 2025.1002.636                
NuGet\Install-Package Redpoint.StringEnum -Version 2025.1002.636                
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="Redpoint.StringEnum" Version="2025.1002.636" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redpoint.StringEnum --version 2025.1002.636                
#r "nuget: Redpoint.StringEnum, 2025.1002.636"                
#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 Redpoint.StringEnum as a Cake Addin
#addin nuget:?package=Redpoint.StringEnum&version=2025.1002.636

// Install Redpoint.StringEnum as a Cake Tool
#tool nuget:?package=Redpoint.StringEnum&version=2025.1002.636                

Redpoint.StringEnum

This library provides an API for defining and using string-backed enumeration types. These are useful when used with databases, where storing string values for enumerations improves forward and backward compatibility (unlike storing numeric values).

Defining a string-backed enumeration type

You can create a string-backed enumeration, by defining a class like so:

class Example : StringEnum<Example>
{
    public static readonly StringEnumValue<Example> FirstValue = Create("first-value");

    public static readonly StringEnumValue<Example> SecondValue = Create("second-value");

    public static readonly StringEnumValue<Example> ThirdValue = Create("third-value");

    // ...
}

The string values that represent the enumeration are case-and-byte sensitive (ordinal comparison). You can not create enumeration values from a null string; ArgumentNullException will be thrown if you pass a null value to Create.

Defining additional enumeration values at runtime

There is currently no API for defining additional enumeration values at runtime; the possible enumeration values are lazy-loaded once by looking at the static fields and static properties of the class that inherits from StringEnum<T> (via the T type parameter). Both public and non-public fields/properties are included.

This library is both trim and AOT-compatible, as it uses [DynamicallyAccessedMembers] to ensure the fields and properties of the enumeration type are available at runtime for reflection.

Static usage of values

In most code, you'll simply use the static readonly fields you've defined, such as Example.FirstValue. All instances of the value - even those from parsing - are guaranteed to be reference and value equal.

Parsing known values from strings

To parse a value that is known to be valid from a string, you can use Example.Parse or StringEnumValue<Example>.Parse:

var value = Example.Parse("first-value");
var value2 = StringEnumValue<Example>.Parse("second-value");

If the value is not valid when calling Parse, StringEnumParseException will be thrown. You should use TryParse (see below) if the value is potentially invalid.

If you pass a null value to Parse, ArgumentNullException will be thrown.

Parsing potentially invalid string values

If you're unsure whether a string is a valid enumeration value, you can use Example.TryParse or StringEnumValue<Example>.TryParse:

var isValid = Example.TryParse("...", out var value);
var isValid2 = StringEnumValue<Example>.TryParse("...", out var value2);

If you pass a null value to TryParse, ArgumentNullException will be thrown.

Parsing strings to runtime-based enumeration types

If you don't know the type of the string enumeration you want to parse into at compile time, you can use DynamicStringEnumValue.TryParse to parse any string value into an instance of StringEnumValue<T> by passing the StringEnumValue<T> type as the first parameter, like so:

var type = typeof(StringEnumValue<Example>);
var isValid = DynamicStringEnumValue.TryParse(type, "...", out var value);

You can use DynamicStringEnumValue.IsStringEnumValueType to check if type is a constructed generic type of StringEnumValue<T>. The APIs provided by DynamicStringEnumValue are primarily intended to be used with database serialization and deserialization, where the concrete types of values are not known at the point of deserialization.

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.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Redpoint.StringEnum:

Package Downloads
Redpoint.CloudFramework

A framework for building ASP.NET Core applications on top of Google Cloud Firestore in Datastore mode. Not only does this framework provide a model-based API for interacting with Google Cloud Firestore, it contains useful implementations of things like database migrations, distributed locks, geographic indexes and sharded counters.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2025.1002.636 33 1/2/2025
2025.1001.1435 41 1/2/2025
2025.1001.1397 35 1/1/2025
2025.1001.770 64 1/1/2025
2025.1001.570 70 1/1/2025
2025.1001.558 59 1/1/2025
2025.1001.421 66 1/1/2025
2025.1001.390 65 1/1/2025
2025.1001.234 79 1/1/2025
2025.1001.123 74 1/1/2025
2024.1360.354 78 12/25/2024
2024.1360.60 73 12/25/2024
2024.1360.32 72 12/25/2024
2024.1358.450 73 12/23/2024
2024.1358.359 74 12/23/2024
2024.1358.312 69 12/23/2024
2024.1358.244 78 12/23/2024
2024.1358.120 66 12/23/2024
2024.1348.253 83 12/13/2024
2024.1345.1379 72 12/10/2024
2024.1345.506 70 12/10/2024
2024.1345.379 69 12/10/2024
2024.1345.145 75 12/10/2024
2024.1345.72 72 12/10/2024
2024.1345.69 68 12/10/2024
2024.1345.15 80 12/10/2024
2024.1344.1436 75 12/10/2024
2024.1344.600 81 12/9/2024
2024.1344.411 81 12/9/2024
2024.1340.379 89 12/5/2024
2024.1340.15 80 12/5/2024
2024.1338.786 89 12/3/2024
2024.1338.722 92 12/3/2024
2024.1338.697 84 12/3/2024
2024.1338.639 85 12/3/2024
2024.1338.541 85 12/3/2024
2024.1338.318 74 12/3/2024
2024.1338.298 77 12/3/2024
2024.1338.98 76 12/3/2024
2024.1337.756 82 12/2/2024
2024.1337.634 89 12/2/2024
2024.1337.625 77 12/2/2024
2024.1337.621 78 12/2/2024
2024.1337.594 79 12/2/2024
2024.1337.136 66 12/2/2024
2024.1336.793 90 12/1/2024
2024.1336.773 89 12/1/2024
2024.1336.305 79 12/1/2024
2024.1336.12 92 12/1/2024
2024.1335.1421 88 11/30/2024
2024.1335.1384 85 11/30/2024
2024.1334.1308 81 11/29/2024
2024.1334.764 77 11/29/2024
2024.1334.722 82 11/29/2024
2024.1330.185 81 11/25/2024
2024.1328.505 87 11/23/2024
2024.1328.470 80 11/23/2024
2024.1328.452 79 11/23/2024
2024.1323.910 93 11/18/2024
2024.1323.653 78 11/18/2024
2024.1323.185 78 11/18/2024
2024.1323.49 75 11/18/2024
2024.1322.714 77 11/17/2024
2024.1320.653 85 11/15/2024
2024.1320.619 78 11/15/2024
2024.1320.601 72 11/15/2024
2024.1320.159 80 11/15/2024
2024.1320.98 80 11/15/2024
2024.1320.2 84 11/15/2024
2024.1319.1431 81 11/15/2024
2024.1319.1335 84 11/14/2024
2024.1317.631 86 11/12/2024
2024.1316.330 92 11/11/2024
2024.1311.540 80 11/6/2024
2024.1306.225 82 11/1/2024
2024.1306.199 87 11/1/2024
2024.1306.171 77 11/1/2024
2024.1306.117 88 11/1/2024
2024.1305.506 75 10/31/2024
2024.1305.502 75 10/31/2024
2024.1305.465 76 10/31/2024
2024.1305.442 78 10/31/2024
2024.1305.399 77 10/31/2024
2024.1299.1070 85 10/25/2024
2024.1289.621 88 10/15/2024
2024.1289.338 86 10/15/2024
2024.1277.836 86 10/5/2024
2024.1277.711 89 10/3/2024
2024.1277.695 85 10/3/2024
2024.1270.409 95 9/26/2024
2024.1269.621 99 9/25/2024
2024.1269.619 88 9/25/2024
2024.1269.605 98 9/25/2024
2024.1242.282 105 8/29/2024
2024.1242.261 101 8/29/2024
2024.1242.233 105 8/29/2024
2024.1238.829 118 8/25/2024
2024.1238.327 122 8/25/2024
2024.1225.297 110 8/12/2024
2024.1205.140 109 7/23/2024
2024.1204.110 105 7/22/2024
2024.1204.62 101 7/22/2024
2024.1190.491 112 7/8/2024
2024.1177.305 106 6/25/2024
2024.1168.700 114 6/16/2024
2024.1168.649 113 6/16/2024
2024.1168.535 119 6/16/2024
2024.1167.643 111 6/15/2024
2024.1166.989 105 6/14/2024
2024.1166.818 109 6/14/2024
2024.1166.535 113 6/14/2024
2024.1166.422 101 6/14/2024
2024.1166.362 108 6/14/2024
2024.1166.360 110 6/14/2024
2024.1165.1212 107 6/13/2024
2024.1165.1160 107 6/13/2024
2024.1165.1019 108 6/13/2024
2024.1165.978 104 6/13/2024
2024.1165.920 104 6/13/2024
2024.1165.908 106 6/13/2024
2024.1165.873 105 6/13/2024
2024.1165.830 105 6/13/2024
2024.1165.806 107 6/13/2024
2024.1165.794 106 6/13/2024
2024.1165.792 110 6/13/2024
2024.1165.761 106 6/13/2024
2024.1165.743 103 6/13/2024
2024.1165.735 106 6/13/2024
2024.1165.713 108 6/13/2024
2024.1165.640 100 6/13/2024
2024.1165.574 106 6/13/2024
2024.1165.466 105 6/13/2024
2024.1165.417 104 6/13/2024
2024.1165.392 102 6/13/2024
2024.1164.341 93 6/12/2024
2024.1155.941 117 6/3/2024
2024.1140.783 119 5/19/2024
2024.1140.692 107 5/19/2024
2024.1140.673 112 5/19/2024
2024.1129.506 106 5/8/2024
2024.1128.831 124 5/7/2024
2024.1124.465 88 5/3/2024
2024.1123.1162 85 5/2/2024
2024.1123.1117 79 5/2/2024
2024.1123.1050 72 5/2/2024
2024.1122.352 110 5/1/2024
2024.1122.233 109 5/1/2024
2024.1115.1101 116 4/24/2024
2024.1115.1048 100 4/24/2024
2024.1115.932 100 4/24/2024
2024.1115.858 111 4/24/2024
2024.1115.665 112 4/24/2024
2024.1115.648 104 4/24/2024
2024.1115.591 111 4/24/2024
2024.1101.390 110 4/10/2024
2024.1100.741 112 4/9/2024
2024.1099.526 118 4/8/2024
2024.1099.466 111 4/8/2024
2024.1098.573 117 4/7/2024
2024.1095.977 119 4/4/2024
2024.1095.847 112 4/4/2024
2024.1095.604 113 4/4/2024
2024.1095.485 130 4/4/2024
2024.1094.930 114 4/3/2024
2024.1094.910 124 4/3/2024
2024.1094.387 126 4/3/2024
2024.1094.313 112 4/3/2024
2024.1093.520 112 4/2/2024
2024.1092.240 112 4/1/2024
2024.1089.1425 129 3/29/2024
2024.1089.983 115 3/29/2024
2024.1089.942 104 3/29/2024
2024.1089.2 120 3/29/2024
2024.1088.1343 115 3/28/2024
2024.1088.1139 116 3/28/2024
2024.1088.875 90 3/28/2024
2024.1088.700 106 3/28/2024
2024.1088.603 118 3/28/2024
2024.1088.590 121 3/28/2024
2024.1088.575 116 3/28/2024
2024.1088.561 115 3/28/2024
2024.1088.506 119 3/28/2024
2024.1088.18 121 3/28/2024
2024.1087.1181 128 3/27/2024
2024.1087.1173 119 3/27/2024
2024.1087.1143 126 3/27/2024
2024.1087.1108 106 3/27/2024
2024.1087.950 116 3/27/2024
2024.1087.939 103 3/27/2024
2024.1087.252 121 3/27/2024
2024.1070.736 120 3/10/2024
2024.1049.1437 123 2/19/2024
2024.1036.571 128 2/5/2024
2024.1036.508 114 2/5/2024
2024.1032.1204 116 2/1/2024
2024.1032.1133 111 2/1/2024
2024.1032.1122 133 2/1/2024
2024.1032.1071 110 2/1/2024
2024.1032.940 106 2/1/2024
2024.1031.912 108 1/31/2024
2024.1031.893 109 1/31/2024
2024.1031.851 98 1/31/2024
2024.1031.829 105 1/31/2024
2024.1031.386 102 1/31/2024
2024.1031.318 124 1/31/2024
2024.1017.460 130 1/17/2024
2024.1017.420 108 1/17/2024
2024.1017.163 113 1/17/2024
2024.1016.414 566 1/16/2024
2024.1012.167 123 1/12/2024
2024.1011.406 122 1/11/2024
2024.1010.315 137 1/10/2024
2023.1358.326 168 12/24/2023
2023.1351.473 128 12/17/2023
2023.1351.445 131 12/17/2023
2023.1351.432 132 12/17/2023
2023.1350.478 131 12/16/2023
2023.1344.600 145 12/10/2023
2023.1344.529 150 12/10/2023
2023.1339.582 143 12/5/2023
2023.1338.1072 152 12/4/2023
2023.1336.844 143 12/2/2023
2023.1335.378 146 12/1/2023
2023.1335.236 139 12/1/2023
2023.1335.203 125 12/1/2023