FastEnum.Extensions.Generator
1.0.0-preview.4
dotnet add package FastEnum.Extensions.Generator --version 1.0.0-preview.4
NuGet\Install-Package FastEnum.Extensions.Generator -Version 1.0.0-preview.4
<PackageReference Include="FastEnum.Extensions.Generator" Version="1.0.0-preview.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
paket add FastEnum.Extensions.Generator --version 1.0.0-preview.4
#r "nuget: FastEnum.Extensions.Generator, 1.0.0-preview.4"
// Install FastEnum.Extensions.Generator as a Cake Addin
#addin nuget:?package=FastEnum.Extensions.Generator&version=1.0.0-preview.4&prerelease
// Install FastEnum.Extensions.Generator as a Cake Tool
#tool nuget:?package=FastEnum.Extensions.Generator&version=1.0.0-preview.4&prerelease
FastEnumToString
Source Generator for enums to create extension methods with basic functionality.
Usage
Use the [Extensions]
on your enums, so the source generator will genrate 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. Yet I tested most of the scenarios for the features (methods) marked with an asterisc (*) in the Features list. If you find any differences please let me know.
Limitations
- Only actively supported .NET versions are supperted. See: supported version list
- .NET Framwork is not supported
- Generation extensions for enums nested in classes with generic type parameters are not supported.
Example
using FastEnum;
namespace ToStringExample;
public class NestingClass
{
[Extensions]
public enum NestedInClassEnum
{
None
}
}
[Extensions]
public enum Color : System.Byte
{
Red,
Green,
Blue,
}
[Extensions, Flags]
public enum Options
{
None = 0,
ToString = 1,
Parse = 2,
HasFlag = 4,
}
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.9.2)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.9.2)
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 |
---|---|---|
1.0.0-preview.4 | 38 | 6/10/2024 |
1.0.0-preview.3 | 52 | 3/27/2024 |
1.0.0-preview.1 | 83 | 9/28/2023 |
Rework of some internals and generated code. Major update on FastToString with format 'F'.
With this fix it will be faster and allocates less memory.
Test cases extended.