Adding ObsoleteAttribute to (or otherwise greylisting) Types that are not under my control?

Is there any way to mark types that I don't control as deprecated in any way? Basically I would like to add ObsoleteAttribute to the types that I don't want to use in my .net project (i.e. SerializableAttribute)

I believe I can do something similar with FxCop, but ideally I would like the compiler to already generate warnings for greylisted Types?

It should be at the Per-Project level, but, unfortunately, “Extension Attributes” do not exist, and adding them to Runtime is too late for ObsoleteAttribute ...

Change: . To clarify, I do not want to block usage types (remember that ObsoleteAttribute generates a warning by default, not an error!), I just want to generate warnings when they are used, as in 99% of cases, it is incorrect to use them (i.e. SerializableAttribute) . In addition, I mean not only .net types, but also some types of third-party manufacturers. This is more a reminder. I guess FxCop is the best choice.

+3
source share
2 answers

There is no direct way to do this; FxCop will be your best choice. However, you can be creative and re-declare the type. Caveat: this is quirky quirky! But this will work:

namespace System.Text {
    [Obsolete("Pah; who wants performance...", true)]
    public class StringBuilder { }
}

! extern alias, . (Activator.CreateInstance), .

+3

, . , ;) .

FxCop . xCop , , , .

, " .net" - , TON . , , ( , ). .

... , .

, .

-1

Source: https://habr.com/ru/post/1737991/


All Articles