Is there a way to create compile time errors if a certain method is called?
As an example, what I'd like to do is prevent code in a certain project from calling System.Configuration.ConfigurationManager.AppSettings(). Is there a way to tag the project or class file to raise a compile time error IF that method is called?
I don't think there is, so my thought is that the only way to do this is to generate an FxCop rule that would flag these calls and do it that way, but I am open to other ideas.
I am using .NET 3.5. Not sure if 4.0 code contracts can do this.
Updates
I am specifically talking about framework methods, not my own, so I cannot mark them as Obsolete.
At this point I don't care about reflection.
Another example is System.Web.HttpUtility.HtmlEncode, which I want to find and replace with Microsoft's AntiXss library, but I'd like to integrate some sort of check process on my build server that would check new code as well.