WebGame.Game.Save C# (CSharp) Method

Save() public method

public Save ( ) : byte[]
return byte[]
        public byte[] Save()
        {
            using (var result = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize(result, this);
                return result.ToArray();
            }
        }

Usage Example

示例#1
0
        public static void SaveNewGame(Game game)
        {
            using (var db = CreateDB())
            {
                db.ExecuteWithParams("insert into game (Status, Serialized, Private) values (@Status, @Serialized, @Private) ", new { Status = game.Status, Serialized = game.Save(), @Private = (game.IsPrivate ? 1 : 0) });
                game.Id = (int)db.LastInsertID;
                if (String.IsNullOrEmpty(game.GameName))
                    game.GameName = "Game #" + game.Id;
            }

            // save the new id
            SaveGame(game);

            // insert into cache
            HttpContext.Current.Cache[game.Id.ToString()] = game;
        }
All Usage Examples Of WebGame.Game::Save