예제 #1
0
 private void SetTypeInfo(Type objType, XmlElement element)
 {
     if (!this.options.UseTypeCache)
     {
         CustomXmlSerializer.WriteTypeToNode(element, objType);
         return;
     }
     CustomXmlSerializerBase.TypeInfo typeInfo;
     if (this.typeCache.TryGetValue(objType, out typeInfo))
     {
         XmlElement onlyElement = typeInfo.OnlyElement;
         if (onlyElement != null)
         {
             typeInfo.WriteTypeId(onlyElement);
             onlyElement.RemoveAttribute("type");
             onlyElement.RemoveAttribute("assembly");
             typeInfo.OnlyElement = null;
         }
         typeInfo.WriteTypeId(element);
         return;
     }
     typeInfo             = new CustomXmlSerializerBase.TypeInfo();
     typeInfo.TypeId      = this.typeCache.Count;
     typeInfo.OnlyElement = element;
     this.typeCache.Add(objType, typeInfo);
     CustomXmlSerializer.WriteTypeToNode(element, objType);
 }
예제 #2
0
        private XmlElement GetTypeInfoNode()
        {
            XmlElement xmlElement = this.doc.CreateElement("TypeCache");

            foreach (KeyValuePair <Type, CustomXmlSerializerBase.TypeInfo> current in this.typeCache)
            {
                if (current.Value.OnlyElement == null)
                {
                    XmlElement xmlElement2 = this.doc.CreateElement("TypeInfo");
                    current.Value.WriteTypeId(xmlElement2);
                    CustomXmlSerializer.WriteTypeToNode(xmlElement2, current.Key);
                    xmlElement.AppendChild(xmlElement2);
                }
            }
            if (!xmlElement.HasChildNodes)
            {
                return(null);
            }
            return(xmlElement);
        }