How to reference an unused parameter?
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.
You can use the following syntax to disable and re-enable specific warnings. Surround the code that declares the unused/unreferenced paramter:
#pragma warning disable <warning-number>
// ... code that declares the unused parameter
#pragma warning restore <warning-number>
Where the <warning-number>
above would be the warning number issued by the compiler that you wish to suppress. Presumably that would be C# warning number 219.