Example #1
0
 /// <inheritdoc />
 public GenericInstanceMethodSignature ImportGenericInstanceMethodSignature(GenericInstanceMethodSignature signature)
 {
     return(new GenericInstanceMethodSignature(signature.GenericArguments.Select(ImportTypeSignature))
     {
         Attributes = signature.Attributes,
     });
 }
 public MethodSpecification(IMethodDefOrRef method, GenericInstanceMethodSignature signature)
     : base(new MetadataToken(MetadataTokenType.MethodSpec))
 {
     _method          = new LazyValue <IMethodDefOrRef>(method);
     _signature       = new LazyValue <GenericInstanceMethodSignature>(signature);
     CustomAttributes = new CustomAttributeCollection(this);
 }
        /// <inheritdoc />
        protected override GenericInstanceMethodSignature GetSignature()
        {
            var reader = _parentModule.DotNetDirectory.Metadata
                         .GetStream <BlobStream>()
                         .GetBlobReaderByIndex(_row.Instantiation);

            return(GenericInstanceMethodSignature.FromReader(_parentModule, reader));
        }
Example #4
0
        public void ResolveTypeGenericParameterWithOnlyMethodShouldThrow()
        {
            var genericInstance = new GenericInstanceMethodSignature();

            genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string)));

            var context = new GenericContext(null, genericInstance);

            var parameter = new GenericParameterSignature(GenericParameterType.Type, 0);

            Assert.Throws <ArgumentOutOfRangeException>(() => context.GetTypeArgument(parameter));
        }
Example #5
0
        public void ResolveMethodGenericParameterWithMethod()
        {
            var genericInstance = new GenericInstanceMethodSignature();

            genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string)));

            var context = new GenericContext(null, genericInstance);

            var parameter = new GenericParameterSignature(GenericParameterType.Method, 0);

            Assert.Equal("System.String", context.GetTypeArgument(parameter).FullName);
        }
Example #6
0
        public bool Equals(GenericInstanceMethodSignature signature1, GenericInstanceMethodSignature signature2)
        {
            if (signature1 == null && signature2 == null)
            {
                return(true);
            }
            if (signature1 == null || signature2 == null)
            {
                return(false);
            }

            return(signature1.Attributes == signature2.Attributes &&
                   EqualsManyTypes(signature1.GenericArguments, signature2.GenericArguments));
        }
Example #7
0
        internal MethodSpecification(MetadataHeader header, MetadataToken token, MetadataRow <uint, uint> row)
            : base(header, token, row)
        {
            var tableStream = header.GetStream <TableStream>();

            _method = new LazyValue <IMethodDefOrRef>(() =>
            {
                var methodToken = tableStream.GetIndexEncoder(CodedIndex.MethodDefOrRef).DecodeIndex(row.Column1);
                return(methodToken.Rid != 0 ? (IMethodDefOrRef)tableStream.ResolveMember(methodToken) : null);
            });

            _signature = new LazyValue <GenericInstanceMethodSignature>(() =>
                                                                        GenericInstanceMethodSignature.FromReader(header, header.GetStream <BlobStream>().CreateBlobReader(row.Column2)));
        }
Example #8
0
        public void ResolveMethodGenericParameterWithTypeAndMethod()
        {
            var genericType = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List <>)), false);

            genericType.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string)));

            var genericMethod = new GenericInstanceMethodSignature();

            genericMethod.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int)));

            var context = new GenericContext(genericType, genericMethod);

            var parameter = new GenericParameterSignature(GenericParameterType.Method, 0);

            Assert.Equal("System.Int32", context.GetTypeArgument(parameter).FullName);
        }
        internal MethodSpecification(MetadataImage image, MetadataRow <uint, uint> row)
            : base(row.MetadataToken)
        {
            _image  = image;
            _method = new LazyValue <IMethodDefOrRef>(() =>
            {
                var encoder     = image.Header.GetStream <TableStream>().GetIndexEncoder(CodedIndex.MethodDefOrRef);
                var methodToken = encoder.DecodeIndex(row.Column1);

                return(image.TryResolveMember(methodToken, out var member) ? (IMethodDefOrRef)member : null);
            });

            _signature = new LazyValue <GenericInstanceMethodSignature>(() =>
                                                                        GenericInstanceMethodSignature.FromReader(image, image.Header.GetStream <BlobStream>().CreateBlobReader(row.Column2)));

            CustomAttributes = new CustomAttributeCollection(this);
        }
        private CilInstruction CloneInstruction(MemberCloneContext context, CilMethodBody clonedBody, CilInstruction instruction)
        {
            var clonedInstruction = new CilInstruction(instruction.Offset, instruction.OpCode);

            switch (instruction.OpCode.OperandType)
            {
            case CilOperandType.InlineBrTarget:
            case CilOperandType.ShortInlineBrTarget:
            case CilOperandType.InlineSwitch:
                // Fix up later when all instructions are added.
                clonedInstruction.Operand = instruction.Operand;
                break;

            case CilOperandType.InlineI:
            case CilOperandType.InlineI8:
            case CilOperandType.InlineNone:
            case CilOperandType.InlineR:
            case CilOperandType.InlineString:
            case CilOperandType.ShortInlineI:
            case CilOperandType.ShortInlineR:
                clonedInstruction.Operand = instruction.Operand;
                break;

            case CilOperandType.InlineField:
                clonedInstruction.Operand = context.Importer.ImportField((IFieldDescriptor)instruction.Operand);
                break;

            case CilOperandType.InlineMethod:
                clonedInstruction.Operand = context.Importer.ImportMethod((IMethodDescriptor)instruction.Operand);
                break;

            case CilOperandType.InlineSig:
                if (instruction.Operand is StandAloneSignature standalone)
                {
                    instruction.Operand = new StandAloneSignature(standalone.Signature switch
                    {
                        MethodSignature signature => context.Importer.ImportMethodSignature(signature),
                        GenericInstanceMethodSignature signature => context.Importer.ImportGenericInstanceMethodSignature(signature),
                        _ => throw new NotImplementedException()
                    });
                }
 /// <summary>
 /// Creates a new reference to a generic instantiation of a method.
 /// </summary>
 /// <param name="method">The method to instantiate.</param>
 /// <param name="signature">The instantiation signature.</param>
 public MethodSpecification(IMethodDefOrRef method, GenericInstanceMethodSignature signature)
     : this(new MetadataToken(TableIndex.MethodSpec, 0))
 {
     Method    = method;
     Signature = signature;
 }