Ignore "Cannot resolve symbol" in Resharper
Say I have a method signature like this:
protected override void Initialize(params object[] parameters)开发者_开发技巧
... and the object can accurately handle all the parameters. When I do the validation of these parameters (say setting them to fields of the class) and one is null
, I'd like to be able to do something like this without a warning from ReSharper:
if (parameters[5] == null)
/* Yields: Cannot resolve symbol 'knownParameterName' */
throw new ArgumentNullException("knownParameterName");
In the context of my app, this warning is ok. Does anyone know what rule I need to ignore?
Have you tried putting the parameter names into a static readonly string array and calling
throw new ArgumentNullException(initializationParameterNames[5]);
?
You could do it like this:
protected override void Initialize(params object[] parameters)
{
for (int paramIndex = 0; paramIndex < initializationParameterNames.Length; paramIndex++)
{
if (parameters.Length <= paramIndex)
throw new ArgumentException("Missing " + initializationParamterNames[paramIndex]);
if (parameters[paramIndex] == null)
throw new ArgumentNullException(initializationParameterNames[paramIndex]);
}
...
}
I don't see anything in the options that would control this, at least not displayed in the options dialog. Have you tried asking on the Resharper forums? They're pretty responsive there.
精彩评论