Is there a way to generate a compiler warning if a method is used outside of a class, but not if it is used inside the class?
Reason: class has some basic behaviour that can be done ahead of time in all but a few method overload circumstances. The idea was to say, it’s fine to do this, but you need to be aware of a few things about how this class works.
One approach is to use the
#pragmadirective.In your class with the ‘raw’ method, add the following line at the top:
Mark your ‘raw’ method with the [Obsolete()] attribute.
So long as your class is the only class declared in the file with the pragma directive, any call to the raw method within that class will not raise a compiler warning. Calls made from other classes (files) will still raise a compiler warning similar to this:
e.g.
Program.cs
Class1.cs
When compiled, I get one compiler warning in Program.cs, not in Class1.cs
Health warning – this will suspend compiler warnings for calls made within Class1 to obsolete methods in other classes as well.