Esempio n. 1
0
        /// <summary>
        /// Create a complete deep copy of the given tree of <c>SvgElement</c> objects.
        /// A new set of elements is created, and if the attributes are cloneable they are deep-copied too.
        /// Since strings and all SvgType classes are cloneable, the new tree is independant of the old.
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        public static SvgElement CloneElement(SvgElement el)
        {
            var clone = (SvgElement)el.GetType().GetConstructor(new Type[0]).Invoke(new object[0]);

            foreach (string key in el.Attributes.Keys)
            {
                clone[key] = el[key].CloneIfPossible();
            }

            foreach (SvgElement ch in el.Children)
            {
                clone.AddChild(CloneElement(ch));
            }

            return(clone);
        }
Esempio n. 2
0
        /// <summary>
        /// Used by LoadFromXML
        /// </summary>
        private static void BuildElementNameDictionary()
        {
            _elementNameDictionary = new Hashtable();

            Assembly asm = Assembly.GetExecutingAssembly();

            Type[] ta = asm.GetExportedTypes();

            foreach (Type t in ta)
            {
                if (t.IsSubclassOf(typeof(SvgElement)))
                {
                    SvgElement e = (SvgElement)t.GetConstructor(new System.Type[0]).Invoke(new object[0]);

                    _elementNameDictionary[e.Name] = e.GetType();
                }
            }
        }
Esempio n. 3
0
        private static void BuildElementNameDictionary()
        {
            SvgFactory._elementNameDictionary = new Hashtable();
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            Type[] exportedTypes = executingAssembly.GetExportedTypes();
            Type[] array         = exportedTypes;
            for (int i = 0; i < array.Length; i++)
            {
                Type type = array[i];
                if (type.IsSubclassOf(typeof(SvgElement)))
                {
                    SvgElement svgElement = (SvgElement)type.GetConstructor(new Type[0]).Invoke(new object[0]);
                    if (svgElement.Name != "?")
                    {
                        SvgFactory._elementNameDictionary[svgElement.Name] = svgElement.GetType();
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create a complete deep copy of the given tree of <c>SvgElement</c> objects.
        /// A new set of elements is created, and if the attributes are cloneable they are deep-copied too.
        /// Since strings and all SvgType classes are cloneable, the new tree is independant of the old.
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        public static SvgElement CloneElement(SvgElement el)
        {
            SvgElement clone = (SvgElement)el.GetType().GetConstructor(new System.Type[0]).Invoke(new object[0]);

            foreach(string key in el.Attributes.Keys)
            {
                object o = el[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                    clone[key] = ((ICloneable)o).Clone();
                else
                    clone[key] = o;
            }

            foreach(SvgElement ch in el.Children)
            {
                clone.AddChild(CloneElement(ch));
            }

            return clone;
        }
Esempio n. 5
0
        public static SvgElement CloneElement(SvgElement el)
        {
            SvgElement svgElement = (SvgElement)el.GetType().GetConstructor(new Type[0]).Invoke(new object[0]);

            foreach (string attname in el.Attributes.Keys)
            {
                object obj = el[attname];
                if (typeof(ICloneable).IsInstanceOfType(obj))
                {
                    svgElement[attname] = ((ICloneable)obj).Clone();
                }
                else
                {
                    svgElement[attname] = obj;
                }
            }
            foreach (SvgElement el2 in el.Children)
            {
                svgElement.AddChild(SvgFactory.CloneElement(el2));
            }
            return(svgElement);
        }
Esempio n. 6
0
        /// <summary>
        /// Create a complete deep copy of the given tree of <c>SvgElement</c> objects.
        /// A new set of elements is created, and if the attributes are cloneable they are deep-copied too.
        /// Since strings and all SvgType classes are cloneable, the new tree is independant of the old.
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        public static SvgElement CloneElement(SvgElement el)
        {
            SvgElement clone = (SvgElement)el.GetType().GetConstructor(new System.Type[0]).Invoke(new object[0]);

            foreach (string key in el.Attributes.Keys)
            {
                object o = el[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                {
                    clone[key] = ((ICloneable)o).Clone();
                }
                else
                {
                    clone[key] = o;
                }
            }

            foreach (SvgElement ch in el.Children)
            {
                clone.AddChild(CloneElement(ch));
            }

            return(clone);
        }