예제 #1
0
 public virtual void AnalyzeXmlNode(XmlNode xmlNode)
 {
     if (xmlNode != null)
     {
         foreach (PropertyInfo info in this.GetPropertyInfoList())
         {
             object[] customAttributes = info.GetCustomAttributes(typeof(XmlMappingAttribute), true);
             if (customAttributes.Length > 0)
             {
                 XmlMappingAttribute attribute = customAttributes[0] as XmlMappingAttribute;
                 if (info.PropertyType.IsSubclassOf(typeof(XmlMappingObject)))
                 {
                     XmlNode          nodeList;
                     XmlMappingObject obj2 = info.PropertyType.GetConstructor(Type.EmptyTypes).Invoke(null) as XmlMappingObject;
                     if (attribute.ObjectType == XmlObjectType.List)
                     {
                         nodeList = this.GetNodeList(xmlNode, attribute.MappingName);
                     }
                     else
                     {
                         nodeList = this.GetChildNode(xmlNode, attribute.MappingName);
                     }
                     obj2.AnalyzeXmlNode(nodeList ?? xmlNode);
                     info.SetValue(this, obj2, null);
                     continue;
                 }
                 if (attribute.ObjectType == XmlObjectType.List)
                 {
                     Type    type  = info.PropertyType.GetGenericArguments()[0];
                     IList   list  = info.PropertyType.GetConstructor(Type.EmptyTypes).Invoke(null) as IList;
                     XmlNode node2 = this.GetNodeList(xmlNode, attribute.MappingName);
                     if (type.IsSubclassOf(typeof(XmlMappingObject)))
                     {
                         foreach (XmlNode node3 in node2.FirstChild.ChildNodes)
                         {
                             XmlMappingObject obj3 = type.GetConstructor(Type.EmptyTypes).Invoke(null) as XmlMappingObject;
                             obj3.AnalyzeXmlNode(node3);
                             list.Add(obj3);
                         }
                     }
                     else
                     {
                         foreach (XmlNode node4 in node2.ChildNodes)
                         {
                             list.Add(this.GetNodeValue(node4, attribute.MappingType));
                         }
                     }
                     info.SetValue(this, list, null);
                     continue;
                 }
                 if (info.PropertyType.IsEnum)
                 {
                     object obj4 = Enum.Parse(info.PropertyType, this.GetNodeValue(xmlNode, attribute.MappingName, attribute.MappingType));
                     info.SetValue(this, obj4, null);
                 }
                 else
                 {
                     if (info.PropertyType.Equals(typeof(string)))
                     {
                         info.SetValue(this, this.GetNodeValue(xmlNode, attribute.MappingName, attribute.MappingType), null);
                         continue;
                     }
                     string str = this.GetNodeValue(xmlNode, attribute.MappingName, attribute.MappingType);
                     if (!string.IsNullOrEmpty(str))
                     {
                         Type conversionType = Nullable.GetUnderlyingType(info.PropertyType) ?? info.PropertyType;
                         info.SetValue(this, Convert.ChangeType(str, conversionType), null);
                     }
                 }
             }
         }
     }
 }