Example #1
0
            public int Compare(PropertyInfo x, PropertyInfo y)
            {
                XmlMappingAttribute attribute  = x.GetCustomAttributes(typeof(XmlMappingAttribute), true)[0] as XmlMappingAttribute;
                XmlMappingAttribute attribute2 = y.GetCustomAttributes(typeof(XmlMappingAttribute), true)[0] as XmlMappingAttribute;

                return(attribute.Index.CompareTo(attribute2.Index));
            }
Example #2
0
 public virtual void BuildXmlNode(XmlDocument doc, ref XmlNode refNode, string subName)
 {
     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)))
             {
                 XmlMappingObject obj2 = info.GetValue(this, null) as XmlMappingObject;
                 if (attribute.ObjectType == XmlObjectType.List)
                 {
                     obj2.BuildXmlNode(doc, ref refNode, attribute.MappingName);
                 }
                 else
                 {
                     XmlNode node = this.CreateElement(doc, attribute.MappingName, "");
                     obj2.BuildXmlNode(doc, ref node, attribute.MappingName);
                     refNode.AppendChild(node);
                 }
                 continue;
             }
             if (attribute.ObjectType == XmlObjectType.List)
             {
                 IList list = info.GetValue(this, null) as IList;
                 foreach (object obj3 in list)
                 {
                     if (obj3 is XmlMappingObject)
                     {
                         XmlMappingObject obj4 = obj3 as XmlMappingObject;
                         if (attribute.ObjectType == XmlObjectType.List)
                         {
                             obj4.BuildXmlNode(doc, ref refNode, attribute.MappingName);
                         }
                         else
                         {
                             XmlNode node2 = this.CreateElement(doc, attribute.MappingName, "");
                             obj4.BuildXmlNode(doc, ref node2, attribute.MappingName);
                             refNode.AppendChild(node2);
                         }
                         continue;
                     }
                     if (obj3 is string)
                     {
                         XmlNode newChild = this.CreateElement(doc, attribute.MappingName, obj3);
                         refNode.AppendChild(newChild);
                     }
                 }
                 continue;
             }
             if (info.PropertyType.IsEnum)
             {
                 int num = (int)info.GetValue(this, null);
                 if (attribute.MappingType == MappingType.Attribute)
                 {
                     refNode.Attributes.Append(this.CreateAttribute(doc, attribute.MappingName, num));
                 }
                 else
                 {
                     refNode.AppendChild(this.CreateElement(doc, attribute.MappingName, num));
                 }
                 continue;
             }
             object obj5 = info.GetValue(this, null);
             if (attribute.MappingType == MappingType.Attribute)
             {
                 refNode.Attributes.Append(this.CreateAttribute(doc, attribute.MappingName, obj5));
             }
             else
             {
                 refNode.AppendChild(this.CreateElement(doc, attribute.MappingName, obj5));
             }
         }
     }
 }
Example #3
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 = System.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);
                     }
                 }
             }
         }
     }
 }