static Animation Deserialize(IDictionary<string, object> obj)
{
if(obj == null)
throw new ArgumentNullException("obj");
var animation = new Animation();
if(!obj.ContainsKey("AnimationName"))
throw new InvalidOperationException("Cannot deserialize an Animation without an AnimationName property");
animation.Name = obj["AnimationName"] as string;
// Deserialize the animation's properties (ignoring any special properties)
foreach(var pair in obj) {
if(String.Compare(pair.Key, "AnimationName", StringComparison.OrdinalIgnoreCase) != 0 &&
String.Compare(pair.Key, "AnimationChildren", StringComparison.OrdinalIgnoreCase) != 0)
animation.Properties.Add(pair.Key, pair.Value != null ? pair.Value.ToString() : null);
}
if(obj.ContainsKey("AnimationChildren")) {
var children = obj["AnimationChildren"] as ArrayList;
if(children != null)
foreach(var c in children) {
var child = c as IDictionary<string, object>;
if(child != null)
animation.Children.Add(Deserialize(child));
}
}
return animation;
}