开发者

Version-sensitive ObsoleteAttribute

开发者 https://www.devze.com 2023-02-24 00:54 出处:网络
The [Obsolete] attribute is very handy for marking classes that have been deprecated in favor of better implementations, but it isn\'t sensitive to the version of .Net that the project is targeting.

The [Obsolete] attribute is very handy for marking classes that have been deprecated in favor of better implementations, but it isn't sensitive to the version of .Net that the project is targeting.

For example, say I'm using a home-rolled ThreadSafeDictionary class for versions of .Net before 4.0. When .Net 4.0 came out it included a new class called ConcurrentDictionary. I'd like to be开发者_JS百科 able to mark ThreadSafeDictionary as [Obsolete] but only if the project is being compiled for .Net 4.0. It doesn't appear that the stock ObsoleteAttribute supports controlling the compiler's warnings by framework version.

Is there any way to do this?


I guess you could roll out your custom attribute and then create a post-build process that examines the compiled code through reflection searching for your attribute.

0

精彩评论

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