EnumConstraints.Fody
0.0.13
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.8
This package targets .NET Framework 4.8. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package EnumConstraints.Fody --version 0.0.13
NuGet\Install-Package EnumConstraints.Fody -Version 0.0.13
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="EnumConstraints.Fody" Version="0.0.13" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EnumConstraints.Fody --version 0.0.13
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EnumConstraints.Fody, 0.0.13"
#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 EnumConstraints.Fody as a Cake Addin #addin nuget:?package=EnumConstraints.Fody&version=0.0.13 // Install EnumConstraints.Fody as a Cake Tool #tool nuget:?package=EnumConstraints.Fody&version=0.0.13
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EnumConstraints.Fody
Validates enum property value.
See Milestones for release notes.
This is an add-in for Fody
It is expected that all developers using Fody become a Patron on OpenCollective. See Licensing/Patron FAQ for more information.
Usage
See also Fody usage.
NuGet installation
Install the EnumConstraints.Fody NuGet package and update the Fody NuGet package:
PM> Install-Package Fody
PM> Install-Package EnumConstraints.Fody
The Install-Package Fody
is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.
Add to FodyWeavers.xml
Add <EnumConstraints/>
to FodyWeavers.xml
<Weavers>
<EnumConstraints/>
</Weavers>
What it does
- Looks for all classes with Properties.
- Generates a new implementations of Set and Get methods.
- Replaces orginal implementations with the new ones.
- The new implementations are using the originals implementations under the hood
Behavior
public enum Status
{
Value1,
Value2,
}
public class Sample
{
public Status Status { get; set;}
}
var sample = new();
sample.Status = Status.Value1; // Valid
sample.Status = (Status)10; // Throws an InvalidEnumValueException
How it works
The orginal lowered code
public class Sample
{
private Status <Status>k__BackingField;
public Status Status
{
get; // Calls get_Status
set; // Calls set_Status
}
public Status get_Status()
{
return <Status>k__BackingField;
}
public void set_Status(Status value)
{
<Status>k__BackingField = value;
}
}
What gets compiled
public class Sample
{
private StringComparison <Status>k__BackingField;
public Status Status
{
get; // Calls get_ConstraintStatus
set; // Calls set_ConstraintStatus
}
public Status get_ConstraintStatus()
{
var value = getStatus();
InvalidEnumValueException.ThrowIfInvalid(value);
return value;
}
public void set_ConstraintStatus(Status value)
{
InvalidEnumValueException.ThrowIfInvalid(value);
set_Status(value);
}
public Status get_Status
{
return <Status>k__BackingField;
}
public void set_Status(Status value)
{
<Status>k__BackingField = value;
}
}
Icon
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos 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 |
---|---|---|
0.1.2 | 390 | 2/19/2024 |
0.1.1 | 121 | 2/19/2024 |
0.1.0 | 136 | 2/18/2024 |
0.0.13 | 113 | 2/18/2024 |
0.0.12 | 126 | 2/18/2024 |
0.0.11 | 112 | 2/18/2024 |
0.0.10 | 108 | 2/18/2024 |
0.0.9 | 125 | 2/18/2024 |
0.0.8 | 116 | 2/18/2024 |
0.0.7 | 120 | 2/18/2024 |
0.0.6 | 117 | 2/18/2024 |
0.0.5 | 122 | 2/18/2024 |
0.0.4 | 124 | 2/18/2024 |
0.0.3 | 120 | 2/17/2024 |
0.0.2 | 114 | 2/17/2024 |
0.0.1 | 122 | 2/17/2024 |