views:

25

answers:

1

I know parameters to attribute declarations have to be a constant expression and resolved at compile time. However, can I play with the concept of 'compile time'? ASP.net has the concept of App_Code folder. It looks from it's description like you can drop .cs files into it, even while the app is running, and it will be brought in and compiled. Is it possible to use this mechanism to dynamically create an Enum or const array that can be used in an attribute declaration?

[SomeAttribute(ValidTypes.SomeType)]
public class Foo
{
}

Basically, I want to dynamically grow the valid types in ValidTypes without having to recompile all components that reference it. And I need to keep it in sync with a list of values in a database table. So, my question is, can I drop a .cs file with the definition for an Enum or const string array into App_Code and have it automagically show up? Or better yet, is the mechanism .Net uses to do this available to be called elsewhere so I don't have to do it in an ASP.Net app?

A: 

even if you could, you'd have to recompile the app to use the added values. sounds like what you want is the code in the attribute to look up the dynamic values.

dave thieben
if my code was... if (constArray.Contains(value)) blah ... it would satisfy the Attribute requirement of having arguments be constants. And if the definition of constArray could be dynamically loaded (or updated) by dropping a .cs file into App_Code, then theoretically it would work without a need to recompile.
Ken Foster