private static void WritePropertySetSchema(XmlWriter writer, PropertySetFormats.PropertySetSchema schema)
 {
     writer.WriteStartElement("PropertySetSchema");
     writer.WriteAttributeString("datasize", schema.DataSize.ToString(CultureInfo.InvariantCulture));
     for (int i = 0; i < schema.Count; i++)
     {
         var property = schema[i];
         var handler  = PropertySetFormats.HandlerFactory.Get(property.Type);
         writer.WriteStartElement("PropertySchema");
         writer.WriteAttributeString("name", GetSymbolName(property.Id));
         writer.WriteAttributeString("type", handler.XmlTag);
         writer.WriteAttributeString("offset", property.Offset.ToString(CultureInfo.InvariantCulture));
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
        private static PropertySetFormats.PropertySet ReadPropertySet(XPathNavigator nav, object parent)
        {
            PropertySetFormats.PropertySetSchema definedSchema = null;
            var rawSchema = nav.SelectSingleNode("PropertySetSchema");

            if (rawSchema != null)
            {
                definedSchema = ReadPropertySetSchema(rawSchema);
            }

            var root = nav.SelectSingleNode("PropertySet");

            if (root == null)
            {
                throw new InvalidOperationException();
            }

            var instance = new PropertySetFormats.PropertySet();

            instance.DefinedSchema = definedSchema;

            instance.Name = root.ParseAttributeSymbol("name");

            instance.Flags = root.ParseAttributeEnum("flags", DataFormats.PropertyCollectionFlags.None);

            instance.Flags &= _NonSetListMask;
            instance.Flags |= DataFormats.PropertyCollectionFlags.IsSet;
            instance.Flags |= GetOwnerFlag(parent);

            instance.SchemaName = root.ParseAttributeSymbol("schema", DataFormats.Symbol.Invalid);

            if (root.ParseAttributeBoolean("skipparentcheck", false) == true)
            {
                instance.Flags |= DataFormats.PropertyCollectionFlags.SkipParentCheck;
            }

            instance.ReferenceCount = root.ParseAttributeUInt16("refs", 0);

            instance.Parents.Clear();
            var rawParents = root.Select("Parent");

            while (rawParents.MoveNext() == true)
            {
                var  rawParent = rawParents.Current;
                uint dummy;
                if (Helpers.TryParseSymbol(rawParent.Value, out dummy) == false)
                {
                    throw new FormatException("failed to parse parent");
                }
                instance.Parents.Add(new DataFormats.ResourceHandle(dummy));
            }

            instance.Properties.Clear();
            instance.DefaultProperties.Clear();

            var rawProperties = root.Select("Property");

            while (rawProperties.MoveNext() == true)
            {
                var rawProperty = rawProperties.Current;

                var name      = rawProperty.ParseAttributeSymbol("name");
                var isDefault = rawProperty.ParseAttributeBoolean("default", false);
                var value     = ParseProperty(rawProperty, instance);
                instance.Properties.Add(name.Id, value);

                if (isDefault == true)
                {
                    instance.DefaultProperties.Add(name.Id);
                }
            }

            return(instance);
        }