I have a C # regex program with three files in it, each of which contains a static class:
1) one static class filled with string dictionaries
static class MyStringDicts { internal static readonly Dictionary<string, string> USstates = new Dictionary<string, string>() { { "ALABAMA", "AL" }, { "ALASKA", "AK" }, { "AMERICAN SAMOA", "AS" }, { "ARIZONA", "AZ" }, { "ARKANSAS", "AR" }
2) The class that compiles these values ββin Regex
public static class Patterns { Public static readonly string StateUS = @"\b(?<STATE>" + CharTree.GenerateRegex(Enumerable.Union( AddrVals.USstates.Keys, AddrVals.USstates.Values)) + @")\b";
3) some code that runs regular expressions based on these lines:
public static class Parser {
I would like to be able to generate 2) both with the T4 template, since all this concatenation is the same with every execution:
@"\b(?<STATE><#=CharTree.GenerateRegex(Enumerable.Union( AddrVals.USstates.Keys, AddrVals.USstates.Values)#>)\b";
This works, but if I create a new MyStringDicts
member or add / remove some values ββfrom its dictionaries, the T4 template will not recognize them until the exception of Patterns.cs from compilation and recompilation. Since Parser
dependent on Patterns
, this is really not an option. I need a T4 conversion to account for changes in other files in the same assembly.
Things I don't want to do:
- Split
MyStringDicts
into your own project. I would like to save the files in one project, since they are a logical unit. - Just move
MyStringDicts
to the beginning of Patterns.cs. I also need MyStringDicts members for other purposes (for example, to search in a dictionary or in other T4 templates).
I took advice here about using T4Toolbox VolatileAssembly
and the like, but it seems to only work in the opposite direction when class files need to be recompiled after editing the T4 template.
I want this to be possible?
edited for clarity