...Could you describe in a few sentences what this code generator allows you to do?...
Regarding that, I will try in several ways-- but the "design process" here in my mind is VERY much "ad hoc" at best, although I do try, and I must say "it works for me" and I make no apology for that but surely "it may
not be for everyone", so buyer beware.
The code allows me to generate utility classes for all semi-static "code-tables", (AKA look-up tables, AKA lists of values), in my database and create IntelliSense access to the members by value not by ID, which allows enforcement of typical
filtering tasks, reporting tasks, etc. It is for, "system-level" values. A typical use is the point it at the asp_Roles table and then calls to User.IsInRole(string roleName) can be made quite easily. So the "hide this button if the user is
an admin" business rule is easy to implement-- Otherwise that roleName "admin" gets hard-coded somewhere. Objections for deletions of values, renaming of values exist. Those can be handled by system-rules, admin workflow, and careful coding--
but, in the end, one still must get around where to be that hardcode "admin" and whether to manage it manually or semi-automatically (such as with this type of code generation)-- where the User.IsInRole() example is, I think a great one
because I have not yet seen a good way other than this to quickly write "hide this button if not in the admin role" rule. Etc. However, this templates set is also, and probably mainly, my first proof-of-concept to use T4 and I plan to use it
as a prototype for future code generation tasks, such as to replace my "create base Manager classes for the Disconnected Linq-To-Sql CodePlex code", which I do now with a custom generator and may just rewrite using T4. Etc.
The "stock" description that I added when I did the upload is as follows...
This is a sample, "UtilityClassGenerationSampleV200908061058.zip". It shows one way to generate utility classes for "code tables" in your database. This sample generates a utility class that allows for consumer-friendly code-value lookup.
The concepts used in this sample can be used in any number of ways. This is is a GEFN-sample, This is not a best-practices-sample. Thanks to Oleg Sych for all this.
Inside, the code is fairly well documented, and here I excerpt...
//The purpose of this template set is to generate helpers that expose code-table values for programmatic access, for filtering etc.
//Note that "Psv" stands for "pipe-separated-values".
//Note that a "code-table" is a AKA "table of values", "table of lookup values", "a lookup table", "a type table", etc.
//Note that a "code-table" here must have a single-column case-insensitive-unique text value.
//Example: To enforce the business rule "all non-US citizens must provide a country-of-birth value", one generally
//either hard-code the value somewhere or do other tricks, each of which is manually maintained. But, we still need the rule.
//Objection: If the code table value gets deleted or changed then you have to recompile.
//Maybe. But the hand-hardcode would break too. This is easier to regenerate. And this risk can be mitigated by admin flow and code.
//This is part of a T4 template set.
//The File.tt uses the Generator.tt and the Generator.tt uses the Template.tt to run.
//The number is the "version" of this template set.
//This generates ".cs" files, not ".vb" files.
//TODO. Set the values below to match your desired project settings.
//This is the namespace that will be used for the the output classes.
myGenerator.CodeUtilityNamespace = "Team.Cle.BusinessLayer.BusinessUtilities";
//This is the prefix that will be used for the the output classnames and filenames.
myGenerator.CodeUtilityPrefix = "";
//This is the suffix that will be used for the the output classnames and filenames.
myGenerator.CodeUtilitySuffix = "Utility";
//This is the database-name to use for all operations.
myGenerator.DatabaseName = "Clea";
//This is the database-server-name to use for all operations.
myGenerator.ServerName = "cen-db";
//This is the list of code-table prefixes, where if a table name starts with any prefix in the list then that table is a "code table".
myGenerator.CodeTablePrefixPsv = "";
//This is the list of code-table suffixes, where if a table name starts with any prefix in the list then that table is a "code table".
myGenerator.CodeTableSuffixPsv = "Code";
//This is the list of column names, where one must exist in each code-table.
myGenerator.CodeValueColumnNamePsv = "Name|NameText";
That's the gist of it, in brain-dump form. I wish it were more polished but it isn't.
-- Mark Kamoski