Exemplo n.º 1
0
        public void OperandTypeSig()
        {
            var methodBody = CreateDummyMethodBody();
            var image      = methodBody.Method.Image;
            var importer   = new ReferenceImporter(image);

            var instructions = methodBody.Instructions;

            var signature = importer.ImportStandAloneSignature(
                new StandAloneSignature(new MethodSignature(image.TypeSystem.Void)
            {
                HasThis = false
            }));

            instructions.AddRange(new[]
            {
                CilInstruction.Create(CilOpCodes.Calli, signature),
                CilInstruction.Create(CilOpCodes.Ret)
            });

            var mapping = image.Header.UnlockMetadata();

            image = image.Header.LockMetadata();

            var newMethod = (MethodDefinition)image.ResolveMember(mapping[methodBody.Method]);

            instructions = newMethod.CilMethodBody.Instructions;

            var newSignature = (StandAloneSignature)instructions[0].Operand;

            Assert.Equal(signature.Signature as MethodSignature, newSignature.Signature as MethodSignature, _comparer);
        }