public static LevelData Parse(string fileName, string serializedData) { string currentField = ""; int currentPosition = 0; LevelData result = new LevelData(); result.FileName = fileName; foreach (string line in serializedData.Split(Environment.NewLine.ToCharArray())) { currentPosition += line.Length; string trimmedLine = line.Trim(); if (trimmedLine.Length > 0) { if (trimmedLine[0] == ';') { currentField = trimmedLine.Substring(1); } else if (trimmedLine == "Board") { result.PuzzleData = BoardData.Parse(serializedData.Substring(currentPosition)); } else if (trimmedLine == "Cube") { result.PuzzleData = CubeData.Parse(serializedData.Substring(currentPosition)); } else { switch (currentField) { case "numberMoves": result.numberMoves = int.Parse(trimmedLine); break; case "firstObjective": result.firstObjective = (ObjectiveType)int.Parse(trimmedLine); break; } } } } return(result); }