I was wondering if you have any tips on how I can debug deserialization below XML? I can not make it work. Deserializer basically creates instances of summon and slash, but all of their properties are empty. Below are the relevant classes.
SkillCollection class with Deserializer:
[DataContract(Name = "Skills", Namespace = "")]
public class SkillCollection
{
[DataMember(Name = "Slash")]
public Skill Slash { get; set; }
[DataMember(Name = "Summon")]
public Skill Summon { get; set; }
public static object Deser(string path, Type toType)
{
var s = new DataContractSerializer(toType);
using (FileStream fs = File.Open(path, FileMode.Open))
{
object s2 = s.ReadObject(fs);
if (s2 == null)
Console.WriteLine(@" Deserialized object is null");
else
Console.WriteLine(@" Deserialized type: {0}", s2.GetType());
return s2;
}
}
It is called from another class through the Skills property:
Skills = (SkillCollection)SkillCollection.Deser(
Path.Combine(path, "Skills.xml"),
typeof(SkillCollection));
Skill Class:
public class Skill
{
[DataMember(Name = "Cast")]
public float Cast { get; set; }
[DataMember(Name = "ReCast")]
public float ReCast { get; set; }
[DataMember(Name = "MPCost")]
public int MpCost { get; set; }
public Timer Timer { get; private set; }
public bool Ready { get; set; }
public Skill()
{
Ready = true;
Timer = new Timer { Interval = ReCast + 500, AutoReset = false };
Timer.Elapsed += OnTimedEvent;
}
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
Ready = true;
}
}
XML file:
<Skills>
<Slash>
<Cast>0.00</Cast>
<ReCast>60.00</ReCast>
<MPCost>0</MPCost>
</Slash>
<Summon>
<Cast>5.98</Cast>
<ReCast>2.49</ReCast>
<MPCost>0</MPCost>
</Summon>
</Skills>
Just because there is no confusion, my goal is to start the deserializer, and then the SkillCollection class contains two Skill instances (Slash and Summon) and have access to them separately through their properties.
Thanks for any help / debugging tips.
source
share