Is there a way to somehow mark Types I do not control as Obsolete? Basically I would like to add ObsoleteAttribute to types I do not want to use in my .net Project (i.e., SerializableAttribute)
I believe I can do something like that with FxCop, but ideally I would like to have the compiler already generate warnings for “greylisted” Types?
This should be on a Per-Project level, but sadly “Extension Attributes” don’t exist, and adding them at Runtime is too late for ObsoleteAttribute…
Edit: Just to clarify, I do not want to block Types from using (keep in mind that ObsoleteAttribute by default only generates a warning, not an error!), I just want to generate warnings when they are used as in 99% of all cases it’s wrong to use them (i.e. SerializableAttribute). Also, I’m not only referring to .net types but also to some third party types. It’s more a reminder. I’ll guess FxCop is my best bet then.
There isn’t a way to do this directly; FxCop would be your best bet. You could get creative, though, and re-declare the type. Caveat: this is dodgy dodgy! But it’ll work:
This is so nasty! But takes an
extern aliasto get around. It might also monkey with some string-based reflection (Activator.CreateInstance) of course.