예제 #1
0
        private static void CreatePacking(SerializerEmitter emitter)
        {
            Action <TracingILGenerator> loadValueEmitter = null;
            TracingILGenerator          il = emitter.GetPackToMethodILGenerator();

            try
            {
                Label target = il.DefineLabel("END_IF");
                Label label2 = il.DefineLabel("END_METHOD");
                il.EmitAnyLdarga(2);
                il.EmitGetProperty(NullableMessagePackSerializer <T> ._nullableTHasValueProperty);
                il.EmitBrtrue_S(target);
                il.EmitAnyLdarg(1);
                il.EmitAnyCall(NullableMessagePackSerializer.PackerPackNull);
                il.EmitPop();
                il.EmitBr_S(label2);
                il.MarkLabel(target);
                if (loadValueEmitter == null)
                {
                    loadValueEmitter = delegate(TracingILGenerator il0) {
                        il0.EmitAnyLdarga(2);
                        il.EmitGetProperty(NullableMessagePackSerializer <T> ._nullableTValueProperty);
                    };
                }
                Emittion.EmitSerializeValue(emitter, il, 1, NullableMessagePackSerializer <T> ._nullableTValueProperty.PropertyType, null, NilImplication.MemberDefault, loadValueEmitter, new LocalVariableHolder(il));
                il.MarkLabel(label2);
                il.EmitRet();
            }
            finally
            {
                il.FlushTrace();
                emitter.FlushTrace();
            }
        }
예제 #2
0
        private static void CreateUnpacking(SerializerEmitter emitter)
        {
            TracingILGenerator unpackFromMethodILGenerator = emitter.GetUnpackFromMethodILGenerator();

            try
            {
                LocalBuilder local    = unpackFromMethodILGenerator.DeclareLocal(typeof(MessagePackObject?), "mayBeNullData");
                LocalBuilder builder2 = unpackFromMethodILGenerator.DeclareLocal(typeof(MessagePackObject), "data");
                LocalBuilder builder3 = unpackFromMethodILGenerator.DeclareLocal(typeof(T), "result");
                LocalBuilder result   = unpackFromMethodILGenerator.DeclareLocal(NullableMessagePackSerializer <T> ._nullableTValueProperty.PropertyType, "value");
                Label        target   = unpackFromMethodILGenerator.DefineLabel("END_IF");
                Label        label2   = unpackFromMethodILGenerator.DefineLabel("END_METHOD");
                unpackFromMethodILGenerator.EmitAnyLdarg(1);
                unpackFromMethodILGenerator.EmitGetProperty(NullableMessagePackSerializer.UnpackerDataProperty);
                unpackFromMethodILGenerator.EmitAnyStloc(local);
                unpackFromMethodILGenerator.EmitAnyLdloca(local);
                unpackFromMethodILGenerator.EmitGetProperty(NullableMessagePackSerializer.Nullable_MessagePackObject_ValueProperty);
                unpackFromMethodILGenerator.EmitAnyStloc(builder2);
                unpackFromMethodILGenerator.EmitAnyLdloca(builder2);
                unpackFromMethodILGenerator.EmitGetProperty(NullableMessagePackSerializer.MessagePackObject_IsNilProperty);
                unpackFromMethodILGenerator.EmitBrfalse_S(target);
                unpackFromMethodILGenerator.EmitAnyLdloca(builder3);
                unpackFromMethodILGenerator.EmitInitobj(builder3.LocalType);
                unpackFromMethodILGenerator.EmitBr_S(label2);
                unpackFromMethodILGenerator.MarkLabel(target);
                Emittion.EmitUnpackFrom(emitter, unpackFromMethodILGenerator, result, 1);
                unpackFromMethodILGenerator.EmitAnyLdloc(result);
                unpackFromMethodILGenerator.EmitAnyCall(NullableMessagePackSerializer <T> ._nullableTImplicitOperator);
                unpackFromMethodILGenerator.EmitAnyStloc(builder3);
                unpackFromMethodILGenerator.MarkLabel(label2);
                unpackFromMethodILGenerator.EmitAnyLdloc(builder3);
                unpackFromMethodILGenerator.EmitRet();
            }
            finally
            {
                unpackFromMethodILGenerator.FlushTrace();
                emitter.FlushTrace();
            }
        }