Beispiel #1
0
        public bool Write(string name, IList value)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            if (value == null)
            {
                return(false);
            }

            var node = _root.OwnerDocument.CreateElement(name);

            for (int i = 0; i < value.Count; i++)
            {
                DXmlWriter writer = new DXmlWriter(node);
                if (!writer.Write("Item", value[i]))
                {
                    return(false);
                }
            }
            _root.AppendChild(node);

            return(true);
        }
Beispiel #2
0
        public bool Write(string name, IDictionary value)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            if (value == null)
            {
                return(false);
            }

            var node = _root.OwnerDocument.CreateElement(name);
            var e    = value.GetEnumerator();

            while (e.MoveNext())
            {
                DXmlWriter keyWriter = new DXmlWriter(node);
                if (!keyWriter.Write("Key", e.Key))
                {
                    return(false);
                }

                DXmlWriter valueWriter = new DXmlWriter(node);
                if (!valueWriter.Write("Value", e.Value))
                {
                    return(false);
                }
            }
            _root.AppendChild(node);

            return(true);
        }
Beispiel #3
0
        private bool WriteObject(string name, Object obj)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            if (obj == null)
            {
                return(false);
            }

            var type      = obj.GetType();
            var listField = DataHelper.GetClassFields(type);

            if (listField == null)
            {
                return(false);
            }

            var        node   = _root.OwnerDocument.CreateElement(name);
            DXmlWriter writer = new DXmlWriter(node);

            for (int i = 0; i < listField.Count; i++)
            {
                var field = listField[i];
                var value = field.GetValue(obj);
                if (value == null)
                {
                    value = DataHelper.Create(field.FieldType);
                }
                if (!writer.Write(field.Name, value))
                {
                    return(false);
                }
            }
            _root.AppendChild(node);

            return(true);
        }