RSCG – PMart.Enumeration
| name | PMart.Enumeration | 
| nuget | https://www.nuget.org/packages/PMart.Enumeration.Generator/ https://www.nuget.org/packages/PMart.Enumeration/ | 
| link | https://github.com/p-martinho/Enumeration | 
| author | Martinho | 
Constants as enumeration. With EFCore,Swagger and other implementations.
This is how you can use PMart.Enumeration .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <PackageReference Include="PMart.Enumeration" Version="3.1.0" /> <PackageReference Include="PMart.Enumeration.Generator" Version="3.1.0" PrivateAssets="all" ExcludeAssets="runtime" /> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
  using DemoPMart;  var personType= PersonType.GetFromValueOrDefault("test"); Console.WriteLine(personType?.Value??"null"); personType = PersonType.GetFromValueOrDefault("manager"); Console.WriteLine(personType!.Value); Console.WriteLine(PersonType.Manager == personType);   
  using PMart.Enumeration.Generator.Attributes;  namespace DemoPMart; [Enumeration] public partial class PersonType {     private static readonly string ValueForEmployee = "Employee";     private static readonly string ValueForManager = "Manager";   }   
The code that is generated is
 // <auto-generated> //     This code was generated by the PMart.Enumeration.Generator source generator. // </auto-generated>  #nullable enable  namespace DemoPMart {     public partial class PersonType : global::PMart.Enumeration.Enumeration<global::DemoPMart.PersonType>     {         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PMart.Enumeration.Generator","3.1.0.0")]         public static readonly global::DemoPMart.PersonType Employee = new global::DemoPMart.PersonType(ValueForEmployee!);          [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PMart.Enumeration.Generator","3.1.0.0")]         public static readonly global::DemoPMart.PersonType Manager = new global::DemoPMart.PersonType(ValueForManager!);          [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PMart.Enumeration.Generator","3.1.0.0")]         private PersonType(string value) : base(value)         {         }     } } 
Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/PMart.Enumeration
Leave a Reply