Git Product home page Git Product logo

engrajabi / enum.source.generator Goto Github PK

View Code? Open in Web Editor NEW
174.0 174.0 14.0 423 KB

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

C# 98.66% Batchfile 1.34%
codegeneration codegenerator csharp-sourcegenerator dotnet enum-fast enum-generator enumgenerator enums fast-enum roslyn roslyn-generator source-generator source-generators

enum.source.generator's Introduction

Hi there, I'm Mohsen Rajabi ๐Ÿ‘‹

Professional skills

csharp dotnetcore dotnet docker kubernetes

  • ๐Ÿ’ฌ Ask me about: .NET, Clean Architecture, Micro Services
  • ๐Ÿ‘ฏ Iโ€™m looking to collaborate on: .NET projects

enum.source.generator's People

Contributors

dameng324 avatar dependabot[bot] avatar engrajabi avatar ohflowi avatar samjib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

enum.source.generator's Issues

Trying to use this to generate enums in more than one csproj

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'.

Dose not work with internal visibility

The generated code has errors, if the used enum has the visibility internal.

Inconsistent accessibility: parameter type ProjectItemType is less accessible than method ProjectItemTypeEnumExtensions.IsDefinedFast(ProjectItemType)

Idea for a new feature

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?

Warning CS1591 : Missing XML comment for publicly visible type or member 'DirectionEnumExtensions'

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?

Should returning false rather than throwing an exception be better behaviour?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.