tags:

views:

46

answers:

2

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?

A: 

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.

James B
+1  A: 

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]);
    }
    ...
}
Jeffrey L Whitledge