Exemplo n.º 1
0
        private bool ReadObject(string name, ref Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

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

            if (_node.Name != name)
            {
                return(false);
            }

            if (!_node.HasChildNodes)
            {
                return(false);
            }

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

            if (listField == null)
            {
                return(false);
            }
            for (int i = 0; i < listField.Count; i++)
            {
                var field     = listField[i];
                var fieldName = field.Name;

                if (_node[fieldName] == null)
                {
                    continue;
                }

                DXmlReader reader = new DXmlReader(_node[fieldName]);

                Type memberType = field.FieldType;
                var  item       = DataHelper.Create(memberType);
                if (!reader.Read(fieldName, ref item))
                {
                    return(false);
                }
                field.SetValue(obj, item);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Dictionary
        ///
        /// <Name>
        ///     <Key></Key>
        ///     <Value></Value>
        /// </Name>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Read(string name, ref IDictionary value)
        {
            if (value == null)
            {
                return(false);
            }

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

            if (_node.Name != name)
            {
                return(false);
            }

            if (!_node.HasChildNodes)
            {
                return(false);
            }

            var type       = value.GetType();
            var paramTypes = type.GetGenericArguments();

            var nodeList = _node.ChildNodes;

            for (int i = 0; i < nodeList.Count; i += 2)
            {
                var        first      = DataHelper.Create(paramTypes[0]);
                DXmlReader keyReader  = new DXmlReader(nodeList[i]);
                string     strKeyName = "Key";
                if (!keyReader.Read(strKeyName, ref first))
                {
                    return(false);
                }

                var        second       = DataHelper.Create(paramTypes[1]);
                DXmlReader valueReader  = new DXmlReader(nodeList[i + 1]);
                string     strValueName = "Value";
                if (!valueReader.Read(strValueName, ref second))
                {
                    return(false);
                }

                value.Add(first, second);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// List
        ///
        /// Sample:
        /// <Name>
        ///     <Item></Item>
        ///     <Item></Item>
        ///     <Item></Item>
        ///     <Item></Item>
        /// </Name>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Read(string name, ref IList value)
        {
            if (value == null)
            {
                return(false);
            }

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

            if (_node.Name != name)
            {
                return(false);
            }

            if (!_node.HasChildNodes)
            {
                return(false);
            }

            var type       = value.GetType();
            var paramTypes = type.GetGenericArguments();

            var nodeList = _node.ChildNodes;

            for (int i = 0; i < nodeList.Count; i++)
            {
                var        first   = DataHelper.Create(paramTypes[0]);
                DXmlReader reader  = new DXmlReader(nodeList[i]);
                string     strName = "Item";
                if (!reader.Read(strName, ref first))
                {
                    return(false);
                }
                value.Add(first);
            }

            return(true);
        }