void HandleSteamCallback(CallbackMsg msg) { var messageMap = new Dictionary<Type, Action<CallbackMsg>> { { typeof(SteamClient.ConnectedCallback), HandleConnected }, { typeof(SteamClient.DisconnectedCallback), HandleDisconnected }, { typeof(SteamUser.LoggedOnCallback), HandleLoggedOn }, { typeof(SteamUser.LoggedOffCallback), HandleLoggedOff }, { typeof(SteamUser.LoginKeyCallback), HandleLoginKey }, { typeof(SteamWeb.WebLoggedOnCallback), HandleWebLoggedOn }, { typeof(SteamFriends.FriendMsgCallback), HandleFriendMessage }, { typeof(SteamFriends.FriendAddedCallback), HandleFriendAdded }, { typeof(SteamTrading.TradeRequestCallback), HandleTradeRequest }, { typeof(SteamTrading.TradeProposedCallback), HandleTradeProposed }, { typeof(SteamGameCoordinator.MessageCallback), HandleGCMessage }, }; Action<CallbackMsg> func; if (!messageMap.TryGetValue(msg.GetType(), out func)) return; func(msg); }
void Handle(CallbackMsg call) { registeredCallbacks .FindAll(callback => callback.CallbackType == call.GetType()) // find handlers interested in this callback .ForEach(callback => callback.Run(call)); // run them }