我有一个接收基本类型参数并根据实际参数类型执行一些预处理的方法。
这是我的代码:
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);
}
// ...
}
一切正常,但我从 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.
避免这些多余演员的最佳方法是什么?