0

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?

Ken Foster
  • 378
  • 4
  • 9
  • http://stackoverflow.com/questions/3357109/whats-the-simplest-most-elegant-way-to-utilize-a-custom-attribute/3357145#3357145 – asawyer Sep 28 '10 at 16:24
  • sorry asawyer but that isn't relevant. I know how to make and use a custom attribute. I am trying to circumvent the issue where attribute arguments have to be statically defined at compile time. – Ken Foster Sep 30 '10 at 14:25

1 Answers1

0

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
  • 5,388
  • 2
  • 28
  • 38
  • 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 Sep 30 '10 at 14:27