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 8087563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:49:02+00:00 2026-06-05T18:49:02+00:00

I have a bunch of strings that are dependent on static dictionaries and each

  • 0

I have a bunch of strings that are dependent on static dictionaries and each other, but are never modified by user code. Something like as follows:

public static RegexDicts
{
  public static readonly Dictionary<string, string> dict = new Dictionary<string, string>{
    {"One", "1"},
    //And so on
  } 
}

public static class RegexStrings
{
  public static readonly string String1 = String.Join("|", RegexDicts.dict.Keys);
  public static readonly string String2 = "Hi! (" + String1 + "(";
  //...
}

Right now, all of these methods have to be executed every time the program executes (even if only once.)

What’s the best way to shift these method executions to the compiler, leaving the actual executable with the intended constants? Even better yet, is it possible to extend this to that dictionary itself – to build the dictionary by reading a file at compile-time?

I’m amicable to doing this with code generation, if I can generate the code and compile it simultaneously.

  • 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-06-05T18:49:03+00:00Added an answer on June 5, 2026 at 6:49 pm

    I’m amicable to doing this with code generation, if I can generate the code and compile it simultaneously.

    You could do this via a T4 template. For details, see Code Generation and T4 Templates.

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

Sidebar

Related Questions

I have a bunch of static Strings that I'd like to store in a
I have a bunch of database addresses and other random long strings that I
I Have a centralised class library that a bunch of my sites use. Each
I have a bunch of strings that I'm writing to a file: private void
I have a file with a bunch of strings that looks like this: new
I have a bunch of strings in a text file that have values in
Basically I have a bunch of large strings that I want to remove spaces/punctuation/numbers
So I have a bunch of strings in records that include the '/' character,
I have a bunch of strings that may or may not have a substring
I have a bunch of strings of mixed length, but all with a year

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.