Back in the days of C/C++, Microsoft had a #define
, which allowed programmers to reference an unused parameter. The declaration, part of windef.h, is:
#define UNREFERENCED_PARAMETER(P) {(P)=(P);}
#define UNREFERENCED_LOCAL_VARIABLE(L) {(L)=(L);}
Whatever the exact name and syntax, the line had the effect of
Is there a similar syntax in C#?
Although it makes no difference for this question, but the DevExpress CodeRush Visual Studio add-in flags all unused parameters, even in event handlers, as a warning.
NOTE:
As I stated in my comment, I do not want to use pragma
blocks. The purpose is to add a line of code that references the parameter for warning sake but adds none to trivial overhead, like what the windef.h header file macro did.
Maybe the discard _
is what you're looking for:
void Foo(string parameter)
{
_ = parameter;
}
Using the SuppressMessage
attribute you can suppress warnings where ever you want:
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isChecked")]
[SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "fileIdentifier")]
static void FileNode(string name, bool isChecked)
{
string fileIdentifier = name;
string fileName = name;
string version = String.Empty;
}
This also gives the reader an explicit understanding that this is intended behavior.
More on the SuppressMessage attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With