Deserialize() public static méthode

public static Deserialize ( XmlNode node ) : Animation
node System.Xml.XmlNode
Résultat Animation
Exemple #1
0
        public static Animation Deserialize(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            // Create the new animation
            Animation animation = new Animation();

            animation.Name = node.Name;

            // Set the properties of the animation
            foreach (XmlAttribute attribute in node.Attributes)
            {
                animation.Properties.Add(attribute.Name, attribute.Value);
            }

            // Add any children (recursively)
            if (node.HasChildNodes)
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    animation.Children.Add(Animation.Deserialize(child));
                }
            }

            return(animation);
        }
        // Convert a series of XML animation descriptions into Animations and assign them to their corresponding
        // Animation properties on a provided ExtenderControl instance.  This will most likely be called by
        // AnimationExtenderControlBase.Animations, but it is publicly exposed so you can call it in the event
        // your extender cannot inherit from AnimationExtenderControlBase.

        // param "value" is
        // sequence of XML animation descriptions (i.e. there should not be a root node because it's expecting the
        // inner contents of the <Animations> tag)
        // param "targetProperties" is target properties that contains the corresponding Animations
        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);
            }
        }
Exemple #3
0
 // Get an animation (which is a helper for Animation properties in other extenders)
 // param "animation" is the Animation instance
 // param "name" is the name of the property
 // returns Animation instance
 protected Animation GetAnimation(ref Animation animation, string name)
 {
     if (animation == null)
     {
         animation = Animation.Deserialize(GetPropertyValue(name, ""));
     }
     return(animation);
 }
        // Convert an XML animation description into an Animation object
        public static Animation Deserialize(XmlNode node)
        {
            if(node == null)
                throw new ArgumentNullException("node");

            var animation = new Animation() {
                Name = node.Name
            };

            // Set the properties of the animation
            foreach(XmlAttribute attribute in node.Attributes)
                animation.Properties.Add(attribute.Name, attribute.Value);

            // Add any children (recursively)
            if(node.HasChildNodes)
                foreach(XmlNode child in node.ChildNodes)
                    animation.Children.Add(Animation.Deserialize(child));

            return animation;
        }