Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6897851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:13:17+00:00 2026-05-27T07:13:17+00:00

So, I feel like it’s possible, but i don’t have the chops to put

  • 0

So, I feel like it’s possible, but i don’t have the chops to put it together. I have lookup tables (with ID and Name fields). I have enums that I keep in sync with the lookups. What I’d like is to make a list of SQL tables, and have roslyn create the enums during/before compile. this way I know my enums are always in sync, and it’s one more thing off my plate.

Could someone out there show me the way, or tell me why it would be a bad idea? I feel like the solution isn’t really a lot of code…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:13:18+00:00Added an answer on May 27, 2026 at 7:13 am

    This is how you create enums with roslyn;

    class Program
    {
        static void Main(string[] args)
        {
            var member1 = Syntax.EnumMemberDeclaration(
                identifier: Syntax.Identifier("Member1")
                );
    
            var declaration = Syntax.EnumDeclaration(
                identifier: Syntax.Identifier("MyEnum"),
                modifiers: Syntax.TokenList(Syntax.Token(SyntaxKind.PublicKeyword)),
                members: Syntax.SeparatedList(member1)
                );
    
            Console.WriteLine(declaration.Format());
            Console.ReadLine();
        }
    }
    

    this returns:

    public enum MyEnum
    {
        Member1
    }
    

    Now to your question, I don’t know if this is what you really need.

    First I think there is not yet any built in functionality to do this at precompile, so you’d need to create a console exe and call it in your prebuild events.

    So at this point probably it is a better idea to do this manually via code generation and not on every build, unless these tables are changing very frequently.

    An in this case you don’t really need roslyn to do it for you, you can just spit it out with any code generation software, or roll your own…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like I'm missing something here, but I have this datagrid which when
I feel like I'm way overthinking this problem, but here goes anyway... I have
I feel like this should have a simple answer, but I can't find it.
I feel like this should be very possible. I have an interface, let's call
I feel like such a noob asking this but, for some reason a horizontal
I feel like I've only ever seen this here on SO, but I can't
I feel like I'm asking a lot of questions, but I keep getting stuck.
I feel like there's a pretty simple way to do this, but I'm not
I feel like I'm missing something obvious, but I can't work out why my
I feel like this is something I should already know, but I'm just not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.