False Positive - DoNotCastUnnecessarily

I think I am getting a false positive here.

Resolution : "'e', a parameter, is cast to type 'IntegrationPluginEngine.JobErrorEventArgs'
multiple times in method Service1.HandleJobEvent(Object,
JobEventArgs):Void. Cache the result of the 'as' operator
or direct cast in order to eliminate the redundant


publicvirtualvoid HandleJobEvent(object sender, JobEventArgs e)
{
if (eis JobErrorEventArgs)
{
LogError(e.Message, ((JobErrorEventArgs)e).Exception, ((Job)sender).ErrorEmail);
}
else
{
LogInfo(e.Message, ((Job)sender).InfoEmail);
}
}


[1044 byte] By [JonathanAllen] at [2007-12-17]
# 1
Hi Jonathan

Your actually casting twice. The first time is the 'is' operator, the second time is the actual cast of 'e'.

The following code should fix the this issue.

public virtual void HandleJobEvent (object sender, JobEventArgs e)
{
JobErrorEventArgs jobErrorArgs = e as JobErrorEventArgs;
if (jobErrorArgs != null)
{
LogError(jobErrorArgs.Message, jobErrorArgs.Exception, ((Job)sender).ErrorEmail);
}
else
{
LogInfo(e.Message, ((Job)sender).InfoEmail);
}
}

Michael

MichaelKoster at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 2
Thanks.

Jonathan

JonathanAllen at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified