FastEnum.Extensions.Generator
1.5.0
dotnet add package FastEnum.Extensions.Generator --version 1.5.0
NuGet\Install-Package FastEnum.Extensions.Generator -Version 1.5.0
<PackageReference Include="FastEnum.Extensions.Generator" Version="1.5.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add FastEnum.Extensions.Generator --version 1.5.0
#r "nuget: FastEnum.Extensions.Generator, 1.5.0"
// Install FastEnum.Extensions.Generator as a Cake Addin #addin nuget:?package=FastEnum.Extensions.Generator&version=1.5.0 // Install FastEnum.Extensions.Generator as a Cake Tool #tool nuget:?package=FastEnum.Extensions.Generator&version=1.5.0
FastEnum.Extensions.Generator
Source Generator for enums to create extension methods with basic functionality.
Usage
Use the [Extensions]
on your enums, so it will generate the extensions for those enums:
Feature
- MembersCount (field)
- GetValues
- GetUnderlyingValues
- GetNames
- HasFlag
- IsDefined
- FastToString
- FastToString with format option
- GetDescription
- TryParse (string/System.ReadOnlySpan<char>)
- TryParseIgnoreCase (string/System.ReadOnlySpan<char>)
Note: I'm trying to make the generated code behave the same as the .NET implementation. If you find any differences, please let me know.
Limitations
- Only currently supported .NET versions are supported. See: supported version list
- .NET Framework is not supported
- Generation extensions for enums nested in classes with generic type parameters are not supported.
- Generation extensions for enums nested in multiple classes is not supported.
Example
using FastEnum;
namespace ToStringExample;
public class NestingClass
{
[Extensions]
public enum NestedInClassEnum
{
None
}
}
[Extensions, Flags]
public enum Color
{
[Description("Crimson Red")]
Red = 0x990000,
[Display(Name = "Pine", Description = "Pine")]
Green = 0x166138,
[EnumMember(Value = "Sky")]
Blue = 0x87CEEB
}
[Extensions, Flags]
public enum GenerationOptions : byte
{
None = 0,
ToString = 1,
Parse = 2,
HasFlag = 4
}
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- No source file is generated for empty enum's, an info analyzer warning is emitted instead.
- Analyzer warning placemnet changed, now the declaration line will be highlighted. (e.g.: "public enum Demo")
- Fixed an error when `System.ComponentModel.DataAnnotations.DisplayAttribute` is used with one named argument (i.e. either `Name` or `Description`) the extension helper wasn't generated.
- Generated code is performance tested and any performance degradation is resolved compared to the .NET implementation.
- Internals updated for more efficient and faster code generation.
- Cosmetic changes in generated code.
- Some generated methods are inlined.