Quickfix/n, most efficient way to extract message Type?

c#, fix-protocol, quickfix

Solution

Not your title question, but a key part of it:

I try to determine the message type within ToAdmin(...) in order to catch an outgoing Logon request message so I can add the username and password.

Here's a blob of code that pretty much nails it (taken from this post to the QF/n mailing list):

    public void ToAdmin(Message message, SessionID sessionID)
    {
        // Check message type
        if (message.Header.GetField(Tags.MsgType) == MsgType.LOGON)
        {
            // Yes it is logon message
            // Check if local variables YourUserName and YourPassword are set
            if (!string.IsNullOrEmpty(YourUserName) && !string.IsNullOrEmpty(YourPassword))
            {
                // Add Username and Password fields to logon message
                ((Logon) message).Set(new Username(YourUserName));
                ((Logon) message).Set(new Password(YourPassword));
            }
        }
    }

Problem

What is the most efficient way in Quickfix/n 1.4 to extract the message type as defined here: http://www.fixprotocol.org/FIXimate3.0/en/FIX.5.0SP2/messages_sorted_by_type.html I currently use `var msgType = Message.GetMsgType(message.ToString());` which results in "A" for a Logon message. Is there a better way? I try to determine the message type within `ToAdmin(...)` in order to catch an outgoing Logon request message so I can add the username and password. I would love to do it through MessageCracker but so far I have not found a way to implement a catch-all-remaining message types in case I have not implemented all OnMessage overloads. (Please see related question: Quickfix, Is there a "catch-all" method OnMessage to handle incoming messages not handled by overloaded methods?). Thanks

Original source