gpt4 book ai didi

c# - 序列化混淆类 C#

转载 作者:太空宇宙 更新时间:2023-11-03 22:01:54 24 4
gpt4 key购买 nike

我目前有一个助手类,我用它来混淆一个静态类,该静态类跟踪我正在开发的游戏中的高分。我在发布时使用 Eazfuscator,发现当我的乐谱被序列化时,抛出了这个异常:

ArgumentException Identifier ' ' is not CLS-compliant

有没有一种方法可以将我的高分列表存储在我的助手类中,并且在混淆之后仍然能够对其进行序列化?

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);
}

我的助手类:

  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);
}
}
}

最佳答案

最好的解决方案是不要混淆任何类型的序列化所需的类。这样做您将获得 2 个好处:

  • 类不会使用奇怪的名字
  • 重新运行混淆不会为相同的类/字段生成新名称。

大多数混淆器允许指定使特定类/方法不被混淆的属性。

否则 - 编写您自己的序列化。

关于c# - 序列化混淆类 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9791443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com