Ejemplo n.º 1
0
        /// <summary>
        /// Xml反序列
        /// </summary>
        /// <param name="mapNode"></param>
        public static ServiceMap XmlDeSerialization(XmlNode mapNode)
        {
            ServiceMap map = new ServiceMap();

            PropertyInfo proInfoT = null;

            foreach (XmlNode resultNode in mapNode.ChildNodes)
            {
                proInfoT = map.GetType().GetProperty(resultNode.Name);
                if (proInfoT != null)
                {
                    proInfoT.SetValue(map,
                                      string.IsNullOrEmpty(resultNode.InnerText)
                        ? null : Convert.ChangeType(resultNode.InnerText, proInfoT.PropertyType), null);
                }
            }

            return(map);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Xml反序列
        /// </summary>
        /// <param name="xmlContent"></param>
        public static ServiceConfigs XmlDeSerialization(string xmlContent)
        {
            ServiceConfigs config = new ServiceConfigs();

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xmlContent);

            XmlNodeList lstNodes = xmlDocument.SelectNodes("ServiceMaps");

            if (lstNodes == null || lstNodes.Count == 0)
            {
                return(config);
            }

            // 获取返回的头部信息
            config.ServiceMaps = new List <ServiceMap>();
            foreach (XmlNode node in lstNodes[0].ChildNodes)
            {
                config.ServiceMaps.Add(ServiceMap.XmlDeSerialization(node));
            }

            return(config);
        }