Ejemplo n.º 1
0
        public void WriteToDynamicMethod(DynamicMethod dynamicMethod, int?maxStack)
        {
            Seal();
            MaxStack = maxStack ?? new MaxStackSizeCalculator(this, ResolveToken).ComputeMaxStack();
            var dynamicILInfo = new DynamicMethodWrapper(dynamicMethod).GetDynamicILInfoWithOldScope();
            var wrapper       = new DynamicILInfoWrapper(dynamicILInfo);
            var code          = new ILCodeBaker(Instructions, wrapper.GetTokenFor).BakeILCode();

            dynamicILInfo.SetCode(code, MaxStack);
            dynamicILInfo.SetLocalSignature(GetLocalSignature());
            if (HasExceptionHandlers)
            {
                dynamicILInfo.SetExceptions(new ExceptionsBaker(ExceptionHandlers, Instructions, wrapper.GetTokenFor).BakeExceptions());
            }
        }
Ejemplo n.º 2
0
        private void WriteMethodBody()
        {
            var ilCode = new ILCodeBaker(body.Instructions, tokenBuilder).BakeILCode();

            codeSize = ilCode.Length;

            if (RequiresFatHeader())
            {
                WriteFatHeader();
            }
            else
            {
                WriteByte((byte)(0x2 | (codeSize << 2))); // tiny
            }
            WriteBytes(ilCode);

            if (body.HasExceptionHandlers)
            {
                Align(4);
                WriteBytes(new ExceptionsBaker(body.ExceptionHandlers, body.Instructions, tokenBuilder).BakeExceptions());
            }
        }