public static void Parse(string value, ExtenderControl extenderControl)
{
if(extenderControl == null)
throw new ArgumentNullException("extenderControl");
if(value == null || String.IsNullOrEmpty(value.Trim()))
return;
// Wrap the XML in a root node (because the Animations node
// isn't included in the content
value = "<Animations>" + value + "</Animations>";
// Parse the animation descriptions
var xml = new XmlDocument();
using(var reader = new XmlTextReader(new StringReader(value))) {
try {
xml.Load(reader);
}
catch(XmlException ex) {
var message = String.Format(CultureInfo.CurrentCulture,
"Invalid Animation definition for TargetControlID=\"{0}\": {1}",
extenderControl.TargetControlID, ex.Message);
throw new HttpParseException(message, new ArgumentException(message, ex),
HttpContext.Current.Request.Path, value, ex.LineNumber);
}
}
foreach(XmlNode node in xml.DocumentElement.ChildNodes) {
var animationProperty = TypeDescriptor.GetProperties(extenderControl)[node.Name];
if(animationProperty == null || animationProperty.IsReadOnly) {
var message = String.Format(CultureInfo.CurrentCulture,
"Animation on TargetControlID=\"{0}\" uses property {1}.{2} that does not exist or cannot be set",
extenderControl.TargetControlID, extenderControl.GetType().FullName, node.Name);
throw new HttpParseException(message, new ArgumentException(message),
HttpContext.Current.Request.Path, value, GetLineNumber(value, node.Name));
}
// Create the animation
if(node.ChildNodes.Count != 1) {
var message = String.Format(CultureInfo.CurrentCulture,
"Animation {0} for TargetControlID=\"{1}\" can only have one child node.",
node.Name, extenderControl.TargetControlID);
throw new HttpParseException(message, new ArgumentException(message),
HttpContext.Current.Request.Path, value, GetLineNumber(value, node.Name));
}
var child = node.ChildNodes[0];
var animation = Animation.Deserialize(child);
// Assign the animation to its property
animationProperty.SetValue(extenderControl, animation);
}
}