コード例 #1
0
 internal static void Serialize(MasterCategoryList mcl, XmlWriter xmlWriter)
 {
     MasterCategoryListSerializer.CatchSerializationException(delegate
     {
         xmlWriter.WriteStartElement("categories", "CategoryList.xsd");
         IEnumerable <PropValue> properties = MasterCategoryListSerializer.GetProperties(new MasterCategoryListSerializer.TryGetPropertyDelegate(mcl.TryGetProperty), MasterCategoryListSchema.Instance.AllProperties);
         MasterCategoryListSerializer.WriteAttributesForProperties(xmlWriter, MasterCategoryListSerializer.PropValuesToAttributeNameValues(properties));
         MasterCategoryListSerializer.WriteCategoryElements(xmlWriter, mcl);
         xmlWriter.WriteEndElement();
     });
 }
コード例 #2
0
 internal void SerializeUsingSource(MasterCategoryList mcl, XmlWriter xmlWriter)
 {
     MasterCategoryListSerializer.CatchSerializationException(delegate
     {
         bool flag = false;
         HashSet <Category> hashSet = new HashSet <Category>(mcl.Count);
         Util.AddRange <Category, Category>(hashSet, mcl);
         this.xmlReader.Read();
         while (!this.xmlReader.EOF)
         {
             if (this.xmlReader.NodeType == XmlNodeType.Element && this.IsFromCategoriesNamespace())
             {
                 this.EnsureLocationIsExpectedForKnownElements(flag);
                 string localName;
                 if ((localName = this.xmlReader.LocalName) != null)
                 {
                     if (localName == "categories")
                     {
                         xmlWriter.WriteStartElement(this.xmlReader.Prefix, this.xmlReader.LocalName, this.xmlReader.NamespaceURI);
                         this.CopyOrOverrideAttributes(xmlWriter, MasterCategoryListSerializer.GetProperties(new MasterCategoryListSerializer.TryGetPropertyDelegate(mcl.TryGetProperty), MasterCategoryListSchema.Instance.AllProperties));
                         flag = true;
                         if (this.xmlReader.IsEmptyElement)
                         {
                             MasterCategoryListSerializer.WriteCategoryElements(xmlWriter, hashSet);
                             xmlWriter.WriteEndElement();
                         }
                         this.xmlReader.Read();
                         continue;
                     }
                     if (localName == "category")
                     {
                         Category category = this.FindMatchingCategory(mcl);
                         if (category != null && hashSet.Contains(category))
                         {
                             xmlWriter.WriteStartElement(this.xmlReader.Prefix, this.xmlReader.LocalName, this.xmlReader.NamespaceURI);
                             this.CopyOrOverrideAttributes(xmlWriter, MasterCategoryListSerializer.GetProperties(new MasterCategoryListSerializer.TryGetPropertyDelegate(category.TryGetProperty), CategorySchema.Instance.AllProperties));
                             if (this.xmlReader.IsEmptyElement)
                             {
                                 xmlWriter.WriteEndElement();
                                 this.xmlReader.Skip();
                             }
                             else
                             {
                                 this.xmlReader.Read();
                                 int depth = this.xmlReader.Depth;
                                 while (this.xmlReader.Depth >= depth)
                                 {
                                     xmlWriter.WriteNode(this.xmlReader, false);
                                 }
                             }
                             hashSet.Remove(category);
                             continue;
                         }
                         this.xmlReader.Skip();
                         continue;
                     }
                 }
                 xmlWriter.WriteNode(this.xmlReader, false);
             }
             else if (this.xmlReader.NodeType == XmlNodeType.EndElement && this.xmlReader.LocalName == "categories")
             {
                 MasterCategoryListSerializer.WriteCategoryElements(xmlWriter, hashSet);
                 xmlWriter.WriteNode(this.xmlReader, false);
             }
             else
             {
                 xmlWriter.WriteNode(this.xmlReader, false);
             }
         }
         if (!flag)
         {
             if (hashSet.Count > 0)
             {
                 ExTraceGlobals.StorageTracer.TraceDebug((long)mcl.GetHashCode(), "The source XML didn't contain the root element we expect. Reverting to source-less serialization.");
                 throw new CorruptDataException(ServerStrings.ExInvalidMclXml);
             }
             this.ReportFault();
         }
     });
 }