开发者

Dynamic parameters for attributes

开发者 https://www.devze.com 2023-01-18 10:44 出处:网络
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

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 att开发者_Go百科ribute 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消