I have a few C# apps that do logging, and the Output method has an overload to accept the message and a StreamWriter, and another overload with an additional parameter for a params array. An example of the method signatures is:
private static void Output(string message, StreamWriter writer, params object[] args)
{..}
private static void Output(string message, StreamWriter writer)
{..}
The question concerns Resharper that gives the following warning for these methods: "Method with optional parameter is hidden by overload".
The warning is misleading because I call the 2-param overload from inside the 3 param overload and it does not result in a recursive call, so the overload is not hidden.
I did some research on the Resharper site and there have been some tickets opened on this issue that have been closed as "will not fix".
It seems to me that this is a valid use case, since the runtime knows which overload to call. Also there are examples in the .NET framework where they use such overloads.
For example, StreamWriter.WriteLine()
has overloads for the value to write, and also Format params
.
Is this a valid argument, or should my methods be renamed to something like "OutputFormat" since behind the scenes they are using string.Format to build a string with the specified params?