Professional skills
- ๐ฌ Ask me about: .NET, Clean Architecture, Micro Services
- ๐ฏ Iโm looking to collaborate on: .NET projects
A C# source generator to create an enumeration class from an enum type. With this package, you can work on enums very, very fast without using reflection.
License: MIT License
If I use this:
public enum UserType
{
[Display(Name = "ู
ุฑุฏ", Description = "men\"")] Men,
The generated code will not compile. Consider use SymbolDisplay.FormatLiteral to properly escape strings.
I would like to have enums generated in separate projects but i am getting this warning and cant seem to find the generated enums
warning CS0436: The type 'EnumGeneratorAttribute' in 'E:\ZiiDMSV2\V2\Client\Common\ReceiptPrinter\obj\Debug\net8.0\Supernova.Enum.Generators\Supernova.Enum.Generators.EnumSourceGenerator\EnumGeneratorAttribute.g.cs' conflicts with the imported type 'EnumGeneratorAttribute' in 'ZiiDMSApp.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'E:\ZiiDMSV2\V2\Client\Common\ReceiptPrinter\obj\Debug\net8.0\Supernova.Enum.Generators\Supernova.Enum.Generators.EnumSourceGenerator\EnumGeneratorAttribute.g.cs'.
The generated code has errors, if the used enum has the visibility internal.
Inconsistent accessibility: parameter type
ProjectItemType
is less accessible than methodProjectItemTypeEnumExtensions.IsDefinedFast(ProjectItemType)
I think it may be useful to have the inverse of ToDisplayFast(), which I have called ToEnumFast(). Here is the pseudo code that should be generated.
public static UnitTests.UserTypeTest ToEnumFast(this string states)
{
return states switch
{
"ู
ุฑุฏ" => UnitTests.UserTypeTest.Men,
"ุฒู" => UnitTests.UserTypeTest.Women,
"None" => UnitTests.UserTypeTest.None,
_ => throw new ArgumentOutOfRangeException()
};
}
Do you like this idea?
my enum is public and I set
<GenerateDocumentationFile>True</GenerateDocumentationFile>
then I got this compile warning:
0>Direction_EnumGenerator.g.cs(6,25): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions'
0>Direction_EnumGenerator.g.cs(8,95): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.DisplayNamesDictionary'
0>Direction_EnumGenerator.g.cs(24,95): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.DisplayDescriptionsDictionary'
0>Direction_EnumGenerator.g.cs(40,30): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.ToStringFast(Direction, string)'
0>Direction_EnumGenerator.g.cs(58,28): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.IsDefinedFast(Direction)'
0>Direction_EnumGenerator.g.cs(76,28): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.IsDefinedFast(string)'
0>Direction_EnumGenerator.g.cs(94,30): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.ToDisplayFast(Direction, string)'
0>Direction_EnumGenerator.g.cs(112,30): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.ToDescriptionFast(Direction, string)'
0>Direction_EnumGenerator.g.cs(130,59): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.GetValuesFast()'
0>Direction_EnumGenerator.g.cs(147,32): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.GetNamesFast()'
0>Direction_EnumGenerator.g.cs(164,27): Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions.GetLengthFast()'
how can I solve this?
The code looks very good, but I think it is more useful if 'IsDefinedFast(string states)' returns false rather than throwing an exception. This means that if the string is not defined in the enum collection and we get back 'false' and can act on that in the if statement.
Here is my example:
// currently throws an exception (would be better if it returned false)
if (UserTypeTestEnumExtensions.IsDefinedFast("Gien"))
{
System.Console.WriteLine("'Gien' is defined");
}
else
{
System.Console.WriteLine("Not defined is 'Gien'");
}
Here is the pseudo code for what I am suggesting:
public static bool IsDefinedFast(string states)
{
return states switch
{
nameof(UnitTests.UserTypeTest.Men) => true,
nameof(UnitTests.UserTypeTest.Women) => true,
nameof(UnitTests.UserTypeTest.None) => true,
_ => false
};
}
This is only for this specific scenario that I suggest returning false.
What do you think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.