Esempio n. 1
0
        public void TestIssue124_AotForComplexValueType()
        {
            MessagePackSerializer.PrepareType <TestValueType>();
            var context =
                PreGeneratedSerializerActivator.CreateContext(
                    SerializationMethod.Array,
                    PackerCompatibilityOptions.None
                    );

            context.Serializers.RegisterOverride(new TestValueTypeWrapperSerializer(context));
            var serializer = MessagePackSerializer.Get <TestValueTypeWrapper>(context);
            var target     = new TestValueTypeWrapper {
                Value = new TestValueType {
                    StringField = String.Empty
                }
            };

            using (var buffer = new MemoryStream())
            {
                serializer.Pack(buffer, target);
                buffer.Position = 0;
                var result = serializer.Unpack(buffer);
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Value.StringField, Is.EqualTo(String.Empty));
                Assert.That(result.Value.Int32ArrayField, Is.Null);
                Assert.That(result.Value.DictionaryField, Is.Null);
            }
        }
Esempio n. 2
0
        private static MessagePackSerializer <T> CreateSerializer <T>(EmitterFlavor flavor)
        {
#if NETFX_35 || NETFX_CORE || SILVERLIGHT
            var context = new SerializationContext();
#else
            var context = PreGeneratedSerializerActivator.CreateContext(SerializationMethod.Array, SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions);
#endif
#if !XAMIOS && !UNITY_IPHONE
            context.SerializerOptions.EmitterFlavor = flavor;
            return(MessagePackSerializer.CreateInternal <T>(context, PolymorphismSchema.Default));
#else
            return(context.GetSerializer <T>());
#endif // !XAMIOS && !UNITY_IPHONE
        }
Esempio n. 3
0
        private static MessagePackSerializer <T> CreateTarget <T>()
        {
#if XAMIOS || XAMDROID || UNITY_ANDROID || UNITY_IPHONE
            return(PreGeneratedSerializerActivator.CreateContext(SerializationMethod.Array, SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions).GetSerializer <T>());
#elif !NETFX_CORE && !SILVERLIGHT
            return(new SerializationContext {
                EmitterFlavor = EmitterFlavor.FieldBased
            }.GetSerializer <T>());
#else
            return(new SerializationContext {
                EmitterFlavor = EmitterFlavor.ExpressionBased
            }.GetSerializer <T>());
#endif
        }
        private static MessagePackSerializer <T> CreateTarget <T>()
        {
#if AOT
            return(PreGeneratedSerializerActivator.CreateContext(SerializationMethod.Array, SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions).GetSerializer <T>());
#elif !SILVERLIGHT
            var context = new SerializationContext();
            context.SerializerOptions.EmitterFlavor = EmitterFlavor.FieldBased;
            return(context.GetSerializer <T>());
#else
            var context = new SerializationContext();
            context.SerializerOptions.EmitterFlavor = EmitterFlavor.ReflectionBased;
            return(context.GetSerializer <T>());
#endif // AOT
        }
Esempio n. 5
0
        private static MessagePackSerializer <T> CreateSerializer <T>(EmitterFlavor flavor)
        {
            var context =
#if AOT
                flavor != EmitterFlavor.ReflectionBased
                                ? PreGeneratedSerializerActivator.CreateContext(SerializationMethod.Array, SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions) :
#endif // AOT
                new SerializationContext();

#if !AOT
            context.SerializerOptions.EmitterFlavor = flavor;
            return(MessagePackSerializer.CreateInternal <T>(context, PolymorphismSchema.Default));
#else
            return(context.GetSerializer <T>());
#endif // !AOT
        }
Esempio n. 6
0
        public void TestIssue99_HoGyuLee_AotForEnumKeyDictionary()
        {
            MessagePackSerializer.PrepareType <FileMode>();
            using (var buffer = new MemoryStream(new byte[] { 0x81, 0x01, 0x00 }))
            {
                var serializer =
                    MessagePackSerializer.Get <Dictionary <FileMode, int> >(
                        PreGeneratedSerializerActivator.CreateContext(
                            SerializationMethod.Array,
                            PackerCompatibilityOptions.None
                            )
                        );
                var result = serializer.Unpack(buffer);
                Assert.That(result.Count, Is.EqualTo(1));
                var singleResult = default(KeyValuePair <FileMode, int>);
                foreach (var kv in result)
                {
                    singleResult = kv;
                }

                Assert.That(singleResult.Key, Is.EqualTo(( FileMode )1));
                Assert.That(singleResult.Value, Is.EqualTo(0));
            }
        }
 private SerializationContext GetSerializationContext()
 {
     return(PreGeneratedSerializerActivator.CreateContext(SerializationMethod.Array, SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions));
 }