我有这个类叫identity
namespace Game.World.Entities
{
[XmlRoot("Identity")]
public class Identity
{
public string Name { get; set; }
public string Texture { get; set; }
public string HeroType { get; set; }
public Stats Stats { get; set; }
public ActiveAbilitites ActiveAbilitites { get; set; }
public PassiveAbilitites PassiveAbilitites { get; set; }
}
public class ActiveAbilitites
{
[XmlElement("AbilityId")]
public List<int> ActiveAbilitiesId { get; set; }
}
public class PassiveAbilitites
{
[XmlElement("AbilityId")]
public List<int> PassiveAbilitiesId { get; set; }
}
public class Stats
{
public int Health { get; set; }
public int MagicDamage { get; set; }
public int PhysicalDamage { get; set; }
public int Defense { get; set; }
}
}
我已经将该类序列化为一个 xml 文档:
<?xml version="1.0" encoding="utf-8"?>
<Identity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>foo</Name>
<Texture>player</Texture>
<HeroType>tracker</HeroType>
<Stats>
<Health>5</Health>
<MagicDamage>5</MagicDamage>
<PhysicalDamage>5</PhysicalDamage>
<Defense>5</Defense>
</Stats>
<ActiveAbilitites>
<AbilityId>1</AbilityId>
<AbilityId>2</AbilityId>
<AbilityId>3</AbilityId>
</ActiveAbilitites>
<PassiveAbilitites>
<AbilityId>1</AbilityId>
<AbilityId>2</AbilityId>
<AbilityId>3</AbilityId>
</PassiveAbilitites>
</Identity>
但是,当我尝试将 xml 反序列化为identity
对象时,出现错误
xml 文档中存在错误 (2,2) .....
System.InvalidOperationException 不是预期的。
在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1.Read6_ArrayOfIdentity()
现在这让我很难过,因为 xml 来自序列化,所以我不知道为什么我不能反序列化它。我假设我在某处错过了一个注释标签,任何关于此事的帮助都会很棒。