void PatchRawFatMethod(ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token)
        {
            var flags = ReadUInt16();

            buffer.WriteUInt16(flags);
            buffer.WriteUInt16(ReadUInt16());
            symbols.code_size = ReadInt32();
            buffer.WriteInt32(symbols.code_size);
            local_var_token = ReadToken();

            if (local_var_token.RID > 0)
            {
                var variables = symbols.variables = ReadVariables(local_var_token);
                buffer.WriteUInt32(variables != null
                                        ? writer.GetStandAloneSignature(symbols.variables).ToUInt32()
                                        : 0);
            }
            else
            {
                buffer.WriteUInt32(0);
            }

            PatchRawCode(buffer, symbols.code_size, writer);

            if ((flags & 0x8) != 0)
            {
                PatchRawSection(buffer, writer.metadata);
            }
        }
		void PatchRawCode (ByteBuffer buffer, int code_size, CodeWriter writer)
		{
			var metadata = writer.metadata;
			buffer.WriteBytes (ReadBytes (code_size));
			var end = buffer.position;
			buffer.position -= code_size;

			while (buffer.position < end) {
				OpCode opcode;
				var il_opcode = buffer.ReadByte ();
				if (il_opcode != 0xfe) {
					opcode = OpCodes.OneByteOpCode [il_opcode];
				} else {
					var il_opcode2 = buffer.ReadByte ();
					opcode = OpCodes.TwoBytesOpCode [il_opcode2];
				}

				switch (opcode.OperandType) {
				case OperandType.ShortInlineI:
				case OperandType.ShortInlineBrTarget:
				case OperandType.ShortInlineVar:
				case OperandType.ShortInlineArg:
					buffer.position += 1;
					break;
				case OperandType.InlineVar:
				case OperandType.InlineArg:
					buffer.position += 2;
					break;
				case OperandType.InlineBrTarget:
				case OperandType.ShortInlineR:
				case OperandType.InlineI:
					buffer.position += 4;
					break;
				case OperandType.InlineI8:
				case OperandType.InlineR:
					buffer.position += 8;
					break;
				case OperandType.InlineSwitch:
					var length = buffer.ReadInt32 ();
					buffer.position += length * 4;
					break;
				case OperandType.InlineString:
					var @string = GetString (new MetadataToken (buffer.ReadUInt32 ()));
					buffer.position -= 4;
					buffer.WriteUInt32 (
						new MetadataToken (
							TokenType.String,
							metadata.user_string_heap.GetStringIndex (@string)).ToUInt32 ());
					break;
				case OperandType.InlineSig:
					var call_site = GetCallSite (new MetadataToken (buffer.ReadUInt32 ()));
					buffer.position -= 4;
					buffer.WriteUInt32 (writer.GetStandAloneSignature (call_site).ToUInt32 ());
					break;
				case OperandType.InlineTok:
				case OperandType.InlineType:
				case OperandType.InlineMethod:
				case OperandType.InlineField:
					var provider = reader.LookupToken (new MetadataToken (buffer.ReadUInt32 ()));
					buffer.position -= 4;
					buffer.WriteUInt32 (metadata.LookupToken (provider).ToUInt32 ());
					break;
				}
			}
		}
		void PatchRawFatMethod (ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token)
		{
			var flags = ReadUInt16 ();
			buffer.WriteUInt16 (flags);
			buffer.WriteUInt16 (ReadUInt16 ());
			symbols.code_size = ReadInt32 ();
			buffer.WriteInt32 (symbols.code_size);
			local_var_token = ReadToken ();

			if (local_var_token.RID > 0) {
				var variables = symbols.variables = ReadVariables (local_var_token);
				buffer.WriteUInt32 (variables != null
					? writer.GetStandAloneSignature (symbols.variables).ToUInt32 ()
					: 0);
			} else
				buffer.WriteUInt32 (0);

			PatchRawCode (buffer, symbols.code_size, writer);

			if ((flags & 0x8) != 0)
				PatchRawSection (buffer, writer.metadata);
		}
        void PatchRawCode(ByteBuffer buffer, int code_size, CodeWriter writer)
        {
            var metadata = writer.metadata;

            buffer.WriteBytes(ReadBytes(code_size));
            var end = buffer.position;

            buffer.position -= code_size;

            while (buffer.position < end)
            {
                OpCode opcode;
                var    il_opcode = buffer.ReadByte();
                if (il_opcode != 0xfe)
                {
                    opcode = OpCodes.OneByteOpCode [il_opcode];
                }
                else
                {
                    var il_opcode2 = buffer.ReadByte();
                    opcode = OpCodes.TwoBytesOpCode [il_opcode2];
                }

                switch (opcode.OperandType)
                {
                case OperandType.ShortInlineI:
                case OperandType.ShortInlineBrTarget:
                case OperandType.ShortInlineVar:
                case OperandType.ShortInlineArg:
                    buffer.position += 1;
                    break;

                case OperandType.InlineVar:
                case OperandType.InlineArg:
                    buffer.position += 2;
                    break;

                case OperandType.InlineBrTarget:
                case OperandType.ShortInlineR:
                case OperandType.InlineI:
                    buffer.position += 4;
                    break;

                case OperandType.InlineI8:
                case OperandType.InlineR:
                    buffer.position += 8;
                    break;

                case OperandType.InlineSwitch:
                    var length = buffer.ReadInt32();
                    buffer.position += length * 4;
                    break;

                case OperandType.InlineString:
                    var @string = GetString(new MetadataToken(buffer.ReadUInt32()));
                    buffer.position -= 4;
                    buffer.WriteUInt32(
                        new MetadataToken(
                            TokenType.String,
                            metadata.user_string_heap.GetStringIndex(@string)).ToUInt32());
                    break;

                case OperandType.InlineSig:
                    var call_site = GetCallSite(new MetadataToken(buffer.ReadUInt32()));
                    buffer.position -= 4;
                    buffer.WriteUInt32(writer.GetStandAloneSignature(call_site).ToUInt32());
                    break;

                case OperandType.InlineTok:
                case OperandType.InlineType:
                case OperandType.InlineMethod:
                case OperandType.InlineField:
                    var provider = reader.LookupToken(new MetadataToken(buffer.ReadUInt32()));
                    buffer.position -= 4;
                    buffer.WriteUInt32(metadata.LookupToken(provider).ToUInt32());
                    break;
                }
            }
        }