基本型のパラメータを受け取り、実際のパラメータ型に応じて前処理を行うメソッドがあります。
これが私のコードです:
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);
}
// ...
}
すべて正常に動作しますが、VisualStudioから次の警告が表示されます。
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.
これらの冗長なキャストを回避するための最良の方法は何ですか?