I was wondering if you had any tips on how I can debug the below XML deserialization? I cannot get it to work. The deserializer basically creates the summon and slash instances, but all their properties are empty. The relevant classes to are shown below.
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 property Skills:
Skills = (SkillCollection)SkillCollection.Deser(
Path.Combine(path, "Skills.xml"),
typeof(SkillCollection));
Skill class:
public class Skill
{
//Cast: time it takes to cast it
[DataMember(Name = "Cast")]
public float Cast { get; set; }
//ReCast: cooldown period before player can cast it again
[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;
}
//Runs when recast is up
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 so there is no confusion, my goal is to run the deserializer, and then have the SkillCollection class contain the two instances of Skill (Slash and Summon), and be able to access them separately through their properties.
Thanks for any help / tips with debugging this.