public void Deserialize(IPofReader reader)
            {
                keysPolymorphic   = reader.ReadBoolean(0);
                valuesPolymorphic = reader.ReadBoolean(1);
                var count = reader.ReadS32(2);
                var data  = reader.ReadBytes(3);

                var context    = reader.Context;
                var serializer = new PofSerializer(context);

                using (var elementStream = new MemoryStream(data))
                    using (var elementStreamReader = new BinaryReader(elementStream)) {
                        Func <TKey> readKey = keysPolymorphic ? new Func <TKey>(() => (TKey)serializer.Deserialize(elementStreamReader))
                                                    : new Func <TKey>(() => (TKey)serializer.Deserialize(elementStreamReader, SerializationFlags.Typeless, typeof(TKey)));
                        Func <TValue> readValue = valuesPolymorphic ? new Func <TValue>(() => (TValue)serializer.Deserialize(elementStreamReader))
                                                        : new Func <TValue>(() => (TValue)serializer.Deserialize(elementStreamReader, SerializationFlags.Typeless, typeof(TValue)));
                        var items = new Dictionary <TKey, TValue>(count);
                        for (var i = 0; i < count; i++)
                        {
                            var key   = readKey();
                            var value = readValue();
                            items.Add(key, value);
                        }
                        this.items = items;
                    }
            }
            public void Deserialize(IPofReader reader)
            {
                isPolymorphic = reader.ReadBoolean(0);
                var length = reader.ReadS32(1);
                var data   = reader.ReadBytes(2);

                var context    = reader.Context;
                var serializer = new PofSerializer(context);

                using (var elementStream = new MemoryStream(data))
                    using (var elementStreamReader = new BinaryReader(elementStream)) {
                        Func <TElement> readElement = isPolymorphic ? new Func <TElement>(() => (TElement)serializer.Deserialize(elementStreamReader))
                                                          : new Func <TElement>(() => (TElement)serializer.Deserialize(elementStreamReader, SerializationFlags.Typeless, typeof(TElement)));
                        elements = Util.Generate(length, i => readElement());
                    }
            }
            public void Serialize(IPofWriter writer)
            {
                writer.WriteBoolean(0, isPolymorphic);
                writer.WriteS32(1, elements.Length);

                var context    = writer.Context;
                var serializer = new PofSerializer(context);

                using (var elementStream = new MemoryStream()) {
                    using (var elementStreamWriter = new BinaryWriter(elementStream, Encoding.UTF8, true)) {
                        var serializationFlags = isPolymorphic ? SerializationFlags.None : SerializationFlags.Typeless;
                        foreach (var element in elements)
                        {
                            serializer.Serialize(elementStreamWriter, element, serializationFlags);
                        }
                    }
                    writer.WriteBytes(2, elementStream.ToArray());
                }
            }
            public void Serialize(IPofWriter writer)
            {
                writer.WriteBoolean(0, keysPolymorphic);
                writer.WriteBoolean(1, valuesPolymorphic);
                writer.WriteS32(2, items.Count);

                var context    = writer.Context;
                var serializer = new PofSerializer(context);

                using (var elementStream = new MemoryStream()) {
                    using (var elementStreamWriter = new BinaryWriter(elementStream, Encoding.UTF8, true)) {
                        var keySerializationFlags   = keysPolymorphic ? SerializationFlags.None : SerializationFlags.Typeless;
                        var valueSerializationFlags = valuesPolymorphic ? SerializationFlags.None : SerializationFlags.Typeless;
                        foreach (var kvp in items)
                        {
                            serializer.Serialize(elementStreamWriter, kvp.Key, keySerializationFlags);
                            serializer.Serialize(elementStreamWriter, kvp.Value, valueSerializationFlags);
                        }
                    }
                    writer.WriteBytes(3, elementStream.ToArray());
                }
            }