I currently have a helper class that I am using to obfuscate a static class that keeps track of high scores in a game I am working on. I am using Eazfuscator on my release and found that when my scores were being serialized, this exception was thrown:
ArgumentException Identifier ' ' is not CLS-compliant
Is there a way I can store my list of high scores in my helper class and still be able to serialize it after obfuscation?
try
{
GameHighScore highScoreHelper = new GameHighScore();
highScoreHelper.CreateGameHighScore(highScore);
XmlSerializer serializer = new XmlSerializer(typeof(GameHighScore));
serializer.Serialize(stream, highScoreHelper);
}
catch(Exception e)
{
Logger.LogError("Score.Save", e);
}
My helper class:
public class GameHighScore
{
public List<HighScoreStruct<string, int>> highScoreList;
private HighScoreStruct<string, int> scoreListHelper;
[XmlType(TypeName = "HighScore")]
public struct HighScoreStruct<K, V>
{
public K Initials
{ get; set; }
public V Score
{ get; set; }
public HighScoreStruct(K initials, V score) : this()
{
Initials = initials;
Score = score;
}
}
public GameHighScore()
{
highScoreList = new List<HighScoreStruct<string, int>>();
scoreListHelper = new HighScoreStruct<string, int>();
}
public void CreateGameHighScore(List<KeyValuePair<string, int>> scoreList)
{
for (int i = 0; i < scoreList.Count; i++)
{
scoreListHelper = new HighScoreStruct<string, int>(scoreList[i].Key, scoreList[i].Value);
highScoreList.Add(scoreListHelper);
}
}
}
Best solution would be not to obfuscate classes needed for any kind of serialization. You'll gain 2 benefits of doing so:
Most obfuscators allow to specify attributes that keep particular classes/methods non-obfuscated.
Otherwise - write your own serialization.