public static void BinaryFormattedResources()
        {
            var values = TestData.BinaryFormatted;

            byte[] writerBuffer, binaryWriterBuffer;
            using (MemoryStream ms = new MemoryStream())
                using (ResourceWriter writer = new ResourceWriter(ms))
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();

                    foreach (var pair in values)
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            binaryFormatter.Serialize(memoryStream, pair.Value);
                            writer.AddResourceData(pair.Key, TestData.GetSerializationTypeName(pair.Value.GetType()), memoryStream.ToArray());
                        }
                    }
                    writer.Generate();
                    writerBuffer = ms.ToArray();
                }

            using (MemoryStream ms = new MemoryStream())
                using (PreserializedResourceWriter writer = new PreserializedResourceWriter(ms))
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();

                    foreach (var pair in values)
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            binaryFormatter.Serialize(memoryStream, pair.Value);
                            writer.AddBinaryFormattedResource(pair.Key, memoryStream.ToArray(), TestData.GetSerializationTypeName(pair.Value.GetType()));
                        }
                    }
                    writer.Generate();
                    binaryWriterBuffer = ms.ToArray();
                }

            // PreserializedResourceWriter should write ResourceWriter/ResourceReader format
            Assert.Equal(writerBuffer, binaryWriterBuffer);

            using (MemoryStream ms = new MemoryStream(writerBuffer, false))
                using (ResourceReader reader = new ResourceReader(ms))
                {
                    typeof(ResourceReader).GetField("_permitDeserialization", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(reader, true);

                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        ResourceValueEquals(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }

            // DeserializingResourceReader can read ResourceReader format
            using (MemoryStream ms = new MemoryStream(writerBuffer, false))
                using (DeserializingResourceReader reader = new DeserializingResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        ResourceValueEquals(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }
        }
        public static void TypeConverterStringResources()
        {
            var values = TestData.StringConverter;

            byte[] binaryWriterBuffer;

            using (MemoryStream ms = new MemoryStream())
                using (PreserializedResourceWriter writer = new PreserializedResourceWriter(ms))
                {
                    foreach (var pair in values)
                    {
                        writer.AddResource(pair.Key, TestData.GetStringValue(pair.Value), TestData.GetSerializationTypeName(pair.Value.GetType()));
                    }
                    writer.Generate();
                    binaryWriterBuffer = ms.ToArray();
                }

            using (MemoryStream ms = new MemoryStream(binaryWriterBuffer, false))
                using (DeserializingResourceReader reader = new DeserializingResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        ResourceValueEquals(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }
        }
        public static void PrimitiveResourcesAsStrings()
        {
            IReadOnlyDictionary <string, object> values = TestData.Primitive;

            byte[] writerBuffer, binaryWriterBuffer;
            using (MemoryStream ms = new MemoryStream())
                using (ResourceWriter writer = new ResourceWriter(ms))
                {
                    foreach (var pair in values)
                    {
                        writer.AddResource(pair.Key, pair.Value);
                    }

                    writer.Generate();
                    writerBuffer = ms.ToArray();
                }

            using (MemoryStream ms = new MemoryStream())
                using (PreserializedResourceWriter writer = new PreserializedResourceWriter(ms))
                {
                    foreach (var pair in values)
                    {
                        writer.AddResource(pair.Key, TestData.GetStringValue(pair.Value), TestData.GetSerializationTypeName(pair.Value.GetType()));
                    }
                    writer.Generate();
                    binaryWriterBuffer = ms.ToArray();
                }

            // PreserializedResourceWriter should write ResourceWriter/ResourceReader format
            Assert.Equal(writerBuffer, binaryWriterBuffer);

            using (MemoryStream ms = new MemoryStream(binaryWriterBuffer, false))
                using (ResourceReader reader = new ResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        Assert.Equal(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }

            // DeserializingResourceReader can read ResourceReader format
            using (MemoryStream ms = new MemoryStream(binaryWriterBuffer, false))
                using (DeserializingResourceReader reader = new DeserializingResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        Assert.Equal(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }
        }