Ejemplo n.º 1
0
 private void VisitXml(string xml, object obj, PropertyInfo[] fields)
 {
     foreach (var field in fields)
     {
         Type subType = field.PropertyType;
         if (!subType.FullName.StartsWith("System."))
         {
             object subObj    = Activator.CreateInstance(subType);// field.GetValue(obj);
             var    subFields = subType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
             field.SetValue(obj, subObj);
             if (subFields.Count() > 0)
             {
                 VisitXml(xml, subObj, subFields);
             }
             else
             {
                 field.SetValue(subObj, XmlTagHelper.GetTagContent(xml, field.Name.FirstToLower(), ""));
             }
         }
         else
         {
             var value = XmlTagHelper.GetTagContent(xml, field.Name.FirstToLower(), "");
             if (subType == typeof(DateTime))
             {
                 field.SetValue(obj, DateTime.Parse(value));
             }
             else
             {
                 field.SetValue(obj, value);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 解析报文
        /// </summary>
        private void Resove(string content)
        {
            var index  = content.IndexOf("<packet>");
            var hIndex = content.IndexOf("</head>");

            if (index == -1 || hIndex == -1 || (index >= hIndex))
            {
                throw new MessageException("响应消息异常");
            }
            string length = content.Substring(0, 6);
            int    len;

            if (!int.TryParse(length, out len))
            {
                throw new MessageException("响应消息异常");
            }
            Length  = len;
            _packet = content.Substring(index);
            _head   = content.Substring(index + 8, hIndex - index - 1);
            Success = XmlTagHelper.GetTagContent(_head, "returnCode", "").Equals("AAAAAAA");
        }