예제 #1
0
        public static XmlNode Add(this XmlNode el, string name, Vector4 pos)
        {
            string str = ((double)pos.X) + "," + pos.Y + "," + pos.Z + "," +
                         pos.W;

            return(el.Add(name, str));
        }
예제 #2
0
        public static XmlNode Add(this XmlNode el, string name, Vector4 pos)
        {
            string str = ((double)pos.X).ToString() + "," + (object)pos.Y + "," + (object)pos.Z + "," +
                         (object)pos.W;

            return(el.Add(name, (object)str, new object[0]));
        }
        public virtual void AddBelow(String child)
        {
            XmlNode childNode = CreateNode(child);

            current.Add(childNode);
            parent  = current;
            current = childNode;
            history.Push(current);
        }
예제 #4
0
        private static void AddPropertiesFromObject(this XmlNode parent, object obj)
        {
            foreach (var prop in obj.GetType().GetProperties())
            {
                object val = prop.GetValue(obj);
                if (val != null && Attribute.GetCustomAttribute(prop, typeof(XmlExcludeAttribute)) == null)
                {
                    var formatAttribute = (XmlFormatAttribute)Attribute.GetCustomAttribute(prop, typeof(XmlFormatAttribute));
                    if (formatAttribute != null)
                    {
                        var method = val.GetType().GetMethod("ToString", new[] { typeof(string) });
                        if (method != null)
                        {
                            val = method.Invoke(val, new[] { formatAttribute.FormatString });
                        }
                        else
                        {
                            throw new Exception($"Cannot apply format string \"{formatAttribute.FormatString}\" to type {prop.PropertyType.FullName}");
                        }
                    }

                    if (prop.PropertyType == typeof(string))
                    {
                        parent.Set(prop.Name, val);
                    }
                    else if (prop.PropertyType.GetInterface(nameof(IEnumerable)) != null)
                    {
                        foreach (object v in (IEnumerable)val)
                        {
                            parent.Add(v.GetType().Name).AddPropertiesFromObject(v);
                        }
                    }
                    else if (prop.PropertyType.IsClass)
                    {
                        parent.Add(prop.PropertyType.Name).AddPropertiesFromObject(val);
                    }
                    else
                    {
                        parent.Set(prop.Name, val);
                    }
                }
            }
        }
        public virtual void AddBeside(String sibling)
        {
            if (current == root)
            {
                throw new SystemException(CANNOT_ADD_BESIDE_ROOT);
            }
            XmlNode siblingNode = CreateNode(sibling);

            parent.Add(siblingNode);
            current = siblingNode;
            history.Pop();
            history.Push(current);
        }