Пример #1
0
        public override Func <SerializationContext, EnumSerializationMethod, MessagePackSerializer <T> > CreateConstructor <T>()
        {
            if (!this._typeBuilder.IsCreated())
            {
                /*
                 *	.ctor( PackerCompatibilityOptions c, EnumSerializerMethod method )
                 *	  : base( c, method )
                 *	{
                 *	}
                 */
                var il = new TracingILGenerator(this._contextConstructorBuilder, TextWriter.Null, this._isDebuggable);
                // : base( c, method )
                il.EmitLdarg_0();
                il.EmitLdarg_1();
                il.EmitLdarg_2();

                Contract.Assert(this._typeBuilder.BaseType != null);

                il.EmitCallConstructor(
                    this._typeBuilder.BaseType.GetConstructor(
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, this._constructorParameterTypes, null
                        )
                    );

                il.EmitRet();
            }

            var ctor             = this._typeBuilder.CreateType().GetConstructor(this._constructorParameterTypes);
            var contextParameter = Expression.Parameter(typeof(SerializationContext), "context");
            var methodParameter  = Expression.Parameter(typeof(EnumSerializationMethod), "method");

#if DEBUG
            Contract.Assert(ctor != null, "ctor != null");
#endif
            return
                (Expression.Lambda <Func <SerializationContext, EnumSerializationMethod, MessagePackSerializer <T> > >(
                     Expression.New(
                         ctor,
                         contextParameter,
                         methodParameter
                         ),
                     contextParameter,
                     methodParameter
                     ).Compile());
        }
        private void EmitMethodEnumConstructor(Type baseType, TracingILGenerator il)
        {
            /*
             *	.ctor( SerializationContext c, EnumSerializerMethod method )
             *	  : base( c, method )
             *	{
             *	}
             */
            // : base( c, method )
            il.EmitLdarg_0();
            il.EmitLdarg_1();
            il.EmitLdarg_2();

            il.EmitCallConstructor(
                baseType.GetRuntimeConstructor(ContextAndEnumSerializationMethodConstructorParameterTypes)
                );

            il.EmitRet();
        }