Esempio n. 1
0
        /// <inheritdoc />
        public override void Compile(AbstractMethodsCompiler methods,
                                     ISerializationMethodStorage <AbstractMethodsCompiler> methodStorage)
        {
            var requiresBoxing = _context.Type.IsPrimitive || _context.Type.IsValueType;
            var gen            = _method.GetILGenerator();

            //var hasValue = gen.DefineLabel();
            //var end = gen.DefineLabel();
            //
            //// If value != null: goto hasValue
            //EmitReadIsNull(gen);
            //gen.Emit(OpCodes.Ldc_I4_0);
            //gen.Emit(OpCodes.Ceq);
            //gen.Emit(OpCodes.Brfalse, hasValue);
            //
            //// return null
            //gen.Emit(OpCodes.Ldnull);
            //gen.Emit(OpCodes.Br_S, end);

            // :hasValue
            // return ReadValueNotNull(reader, serializer, remoteEndPoint);
            //gen.MarkLabel(hasValue);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldarg_1);
            gen.Emit(OpCodes.Ldarg_2);
            gen.Emit(OpCodes.Call, methods.ReadValueMethod);

            if (requiresBoxing)
            {
                gen.Emit(OpCodes.Box, _context.Type);
            }

            //gen.MarkLabel(end);
            gen.Emit(OpCodes.Ret);
        }
        /// <inheritdoc />
        public override void Compile(AbstractMethodsCompiler methods, ISerializationMethodStorage <AbstractMethodsCompiler> methodStorage)
        {
            var serializationType = _context.TypeDescription.SerializationType;

            switch (serializationType)
            {
            case SerializationType.ByValue:
                if (_context.TypeDescription.IsBuiltIn)
                {
                    EmitReadBuiltInType(methodStorage);
                }
                else
                {
                    EmitReadByValue(methodStorage);
                }
                break;

            case SerializationType.ByReference:
                EmitReadByReference();
                break;

            case SerializationType.Singleton:
                EmitReadSingleton();
                break;

            case SerializationType.NotSerializable:
                throw new NotImplementedException();

            case SerializationType.Unknown:
                throw new NotImplementedException();

            default:
                throw new InvalidEnumArgumentException("", (int)serializationType, typeof(SerializationType));
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public override void Compile(AbstractMethodsCompiler methods1,
                                     ISerializationMethodStorage <AbstractMethodsCompiler> methodStorage)
        {
            var methods           = methodStorage.GetOrAdd(Type);
            var writeValueNotNull = methods.WriteValueMethod;

            var gen = Method.GetILGenerator();

            //gen.EmitWriteLine("writing type info");

            //var result = gen.DeclareLocal(typeof(bool));
            //
            //// if (object == null)
            //var @true = gen.DefineLabel();
            //gen.Emit(OpCodes.Ldarg_1);
            //gen.Emit(OpCodes.Ldnull);
            //gen.Emit(OpCodes.Ceq);
            //gen.Emit(OpCodes.Ldc_I4_0);
            //gen.Emit(OpCodes.Ceq);
            //gen.Emit(OpCodes.Stloc, result);
            //gen.Emit(OpCodes.Ldloc, result);
            //gen.Emit(OpCodes.Brtrue, @true);
            //
            //// Writer.Write(null)
            //// goto end
            //EmitWriteNull(gen);
            //var end = gen.DefineLabel();
            //gen.Emit(OpCodes.Br, end);
            //
            //// Writer.Write(type)
            //gen.MarkLabel(@true);
            //EmitWriteTypeInformation(gen);

            // WriteValueNotNull(writer, value, serializer, remotingEndPoint);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldarg_1);

            if (Type.IsPrimitive || Type.IsValueType)
            {
                gen.Emit(OpCodes.Unbox_Any, Type);
            }
            else
            {
                gen.Emit(OpCodes.Castclass, Type);
            }

            gen.Emit(OpCodes.Ldarg_2);
            gen.Emit(OpCodes.Ldarg_3);
            gen.Emit(OpCodes.Call, writeValueNotNull);

            //gen.MarkLabel(end);
            gen.Emit(OpCodes.Ret);
        }
 /// <inheritdoc />
 public abstract void Compile(AbstractMethodsCompiler methods,
                              ISerializationMethodStorage <AbstractMethodsCompiler> methodStorage);