Any way to generate a compiler warning for unused users?
If you are using ReSharper , it will show unused names in a different color by default (as a warning in the error analysis sidebar), and if you highlight them, you can change them to show them as errors. Unfortunately this will not prevent compilation, but it warns you that they are not being used.
source to share
We try to create warnings for situations where the code in question is almost certainly broken, misleading, or useless. Also, since many people are compiled with "warnings as errors" we have a high bar; it is bad to introduce a false or unnecessary warning.
Imagine compiling with warnings enabled by default as errors. Imagine that we have implemented the function you want. You start a new project and we generate for you:
using System;
using System.Text;
using System.Linq;
class Program
{
static void Main(string[] arguments)
{
}
}
and we will immediately inform you that you have a bug in your program, because none of the "tricks" are needed! This is a very bad user experience . Those "usings" are put there by the IDE for your convenience, so you don't need to define them yourself. Your suggested function will turn this from convenience to nag.
source to share
No, because this is not a compiler issue, so you cannot generate compiler warnings. Compiler warnings are only generated when a code dead spot is found, such as an empty catch statement. Or an unused variable. Basically anything that can cause runtime problems. Since the use of statements has nothing to do with the runtime and more text file style problems, they won't generate warnings.
But you can use a tool like reSharper to alert you to unused operators.
source to share