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); } }
|
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