protected override MethodInfo GenerateInner()
        {
            var dynamicMethod = new DynamicMethod(name, returnType, parameterTypes, typeof(Serializer), true);
            var generator     = dynamicMethod.GetILGenerator();
            var context       = new ReaderGenerationContext(generator, disableStamping, treatCollectionAsUserObject, objectIdArgument, objectReaderArgument);

            InnerGenerate(context);
            context.Generator.Emit(OpCodes.Ret);
#if DEBUG_FORMAT
            GeneratorHelper.DumpToLibrary <T>(context, x => InnerGenerate((ReaderGenerationContext)x), name);
#endif
            return(dynamicMethod);
        }
        protected override MethodInfo GenerateInner()
        {
            DynamicMethod dynamicMethod;

            if (type.IsArray)
            {
                dynamicMethod = new DynamicMethod("Read", returnType, parameterTypes, true);
            }
            else
            {
                dynamicMethod = new DynamicMethod("Read", returnType, parameterTypes, type, true);
            }
            var generator = dynamicMethod.GetILGenerator();
            var context   = new ReaderGenerationContext(generator, disableStamping, treatCollectionAsUserObject, OpCodes.Ldarg_2, OpCodes.Ldarg_0);

            GenerateDynamicCode(context, type);

#if DEBUG_FORMAT
            GeneratorHelper.DumpToLibrary <ReadMethodDelegate>(context, c => GenerateDynamicCode((ReaderGenerationContext)c, type));
#endif

            return(dynamicMethod);
        }
Example #3
0
        protected override MethodInfo GenerateInner()
        {
            DynamicMethod dynamicMethod = null;

            if (!type.IsArray)
            {
                dynamicMethod = new DynamicMethod(string.Format("Write_{0}", type.Name), returnType, parameterTypes, type, true);
            }
            else
            {
                var methodNo = Interlocked.Increment(ref WriteArrayMethodCounter);
                dynamicMethod = new DynamicMethod(string.Format("WriteArray{0}_{1}", methodNo, type.Name), returnType, parameterTypes, true);
            }
            var generator = dynamicMethod.GetILGenerator();
            var context   = new WriterGenerationContext(generator, false, treatCollectionAsUserObject, OpCodes.Ldarg_0);

#if DEBUG_FORMAT
            GeneratorHelper.DumpToLibrary <WriteMethodDelegate>(context, c => GenerateDynamicCode((WriterGenerationContext)c, type), type.Name);
#endif
            GenerateDynamicCode(context, type);

            return(dynamicMethod);
        }