tags:

views:

325

answers:

2

I'm trying to find a way to generate an enums class dynamically from lookup tables in a database and still have the convenience of a normal class (i.e. intellisense).

I've spent the past few hours trying to figure out how to get a custom BuildProvider to work inside an ASP.NET Web Application. The code works perfectly in a Web Site. I then found an article on MSDN (http://msdn.microsoft.com/en-us/library/system.web.compilation.buildprovider.aspx) that says 'Adding a customized BuildProvider class to the Web.config file works in an ASP.NET Web site but does not work in an ASP.NET Web application project. In a Web application project, the code that is generated by the BuildProvider class cannot be included in the application. For more information, see Compiling Web Application Projects.'.

Does anyone know if it is possible to generate code dynamically and still be able to 'use' it at design time? Using a web site is not an option. I need to use a web project.

Thanks!!

A: 

If MSDN is saying you can't do it, I'd take another approach. Maybe write a small Console application that writes your Enums.cs file and run it through the "Pre-build event command line". Then, every time you build the web application, the Enums class gets recreated and should be accessible through Intellisense.

Haven't done this myself. Hope it helps.

Gene
+1  A: 

what is the point of an enum class for a dynamic lookup table? your code references will always be static anyway...

if the initial population of the lookup table is static, make an enum for that and don't reference any other values in the code

Steven A. Lowe