Is there a way to create compile-time errors if a specific method is called?
As an example, what I would like to do is to prevent the code in a specific project from calling System.Configuration.ConfigurationManager.AppSettings (). Is there a way to mark a project or class file to raise a compile-time error if this method is called?
I donβt think there is, so I think the only way to do this is to create an FxCop rule that will mark these calls and do it this way, but I am open to other ideas.
I am using .NET 3.5. Not sure if contract with code 4.0 can do this.
Updates
I specifically talk about structure methods, not about myself, so I cannot mark them as obsolete.
At this moment, I do not care about reflection.
Another example is System.Web.HttpUtility.HtmlEncode, which I want to find and replace in the Microsoft AntiXss library, but I would like to integrate some kind of verification process on my build server, which would also check the new code.
source share