Hello guys.
I have a method which receives a parameter of base type and performs some pre-processing depending on actual parameter type.
Here is my code:
public void OnMessageReceived(QuickFix42.Message message)
{
if (message is QuickFix42.ExecutionReport)
{
ProcessExecutionReport(message as QuickFix42.ExecutionReport);
}
else if (message is QuickFix42.AllocationACK)
{
ProcessAllocationAck(message as QuickFix42.AllocationACK);
}
else if (message is QuickFix42.OrderCancelReject)
{
ProcessOrderCancelReject(message as QuickFix42.OrderCancelReject);
}
// ...
}
Everything works fine, but I get the following warning from Visual Studio:
Warning 760 CA1800 : Microsoft.Performance : 'message', a parameter, is cast to type 'ExecutionReport' multiple times in method 'MessageProcessor.OnMessageReceived(Message)'. Cache the result of the 'as' operator or direct cast in order to eliminate the redundant isint instruction.
What's the best way to avoid these redundant casts?