Source Generator for enums to create extension methods with basic functionality.
Use the [Extensions]
on your enums, so it will generate the extensions for those enums:
- MembersCount (field)
- GetValues
- GetUnderlyingValues
- GetNames
- HasFlag
- IsDefined
- FastToString
- FastToString with format option
- GetDescription
- TryParse (string/System.ReadOnlySpan)
- TryParseIgnoreCase (string/System.ReadOnlySpan)
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.
- 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.
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
}