private static void WritePropertyList(XmlWriter writer, PropertySetFormats.PropertyList data) { bool hasWeights = data.Weights.Count > 0; if (data.TotalWeight != 0) { if (data.TotalWeight != data.Weights.Sum(w => w)) { throw new InvalidOperationException(); } } var ignoredFlags = DataFormats.PropertyCollectionFlags.OwnerIsList | DataFormats.PropertyCollectionFlags.IsList | DataFormats.PropertyCollectionFlags.OwnerIsSet; var cleanedFlags = data.Flags & ~ignoredFlags; if (cleanedFlags != DataFormats.PropertyCollectionFlags.None) { writer.WriteAttributeString("flags", cleanedFlags.ToString()); } for (int i = 0; i < data.Items.Count; i++) { writer.WriteStartElement("ListProperty"); WriteProperty(writer, null, data.Items[i], false, hasWeights == false ? (uint?)null : data.Weights[i]); writer.WriteEndElement(); } }
private static PropertySetFormats.PropertyList ReadPropertyList(XPathNavigator nav, object parent) { var instance = new PropertySetFormats.PropertyList(); instance.Flags = nav.ParseAttributeEnum("flags", DataFormats.PropertyCollectionFlags.None); instance.Flags &= _NonSetListMask; instance.Flags |= DataFormats.PropertyCollectionFlags.IsList; instance.Flags |= GetOwnerFlag(parent); var rawProperties = nav.Select("ListProperty"); while (rawProperties.MoveNext() == true) { var rawProperty = rawProperties.Current; var value = ParseProperty(rawProperty, instance); instance.Items.Add(value); var weight = rawProperty.ParseAttributeUInt32("weight", uint.MaxValue); if (weight != uint.MaxValue) { instance.Weights.Add(weight); } } instance.TotalWeight = instance.Weights.Aggregate <uint, uint>(0, (c, w) => c + w); if (instance.Items.Count == 0) { instance.TypeId = 29; } else { var type = instance.Items.First().GetType(); if (instance.Items.Any(i => i.GetType() != type)) { throw new InvalidOperationException(); } instance.TypeId = PropertySetFormats.HandlerFactory.Get(type).Id; } return(instance); }