Ejemplo n.º 1
0
        public ImmutableArray <TType> DecodeSignature <TType>(ISignatureTypeProvider <TType> provider, SignatureDecoderOptions options = SignatureDecoderOptions.None)
        {
            var decoder    = new SignatureDecoder <TType>(provider, _reader, options);
            var blobReader = _reader.GetBlobReader(Signature);

            return(decoder.DecodeMethodSpecificationSignature(ref blobReader));
        }
Ejemplo n.º 2
0
        [InlineData(new byte[] { 0x0A /*GENERICINST*/, 0 /*count*/ })] // no type parameters
        public unsafe void DecodeInvalidMethodSpecificationSignature(byte[] testSignature)
        {
            fixed(byte *testSignaturePtr = &testSignature[0])
            {
                var signatureBlob = new BlobReader(testSignaturePtr, testSignature.Length);
                var provider      = new OpaqueTokenTypeProvider();
                var decoder       = new SignatureDecoder <string>(provider);

                Assert.Throws <BadImageFormatException>(() => decoder.DecodeMethodSpecificationSignature(ref signatureBlob));
            }
        }
        public unsafe void DecodeValidMethodSpecificationSignature(string[] expectedTypes, byte[] testSignature)
        {
            fixed(byte *testSignaturePtr = &testSignature[0])
            {
                var signatureBlob = new BlobReader(testSignaturePtr, testSignature.Length);
                var provider      = new OpaqueTokenTypeProvider();
                var decoder       = new SignatureDecoder <string, DisassemblingGenericContext>(provider, metadataReader: null, genericContext: null);

                IEnumerable <string> actualTypes = decoder.DecodeMethodSpecificationSignature(ref signatureBlob);

                Assert.Equal(expectedTypes, actualTypes);
                Assert.True(signatureBlob.RemainingBytes == 0);
                Assert.Throws <BadImageFormatException>(() => decoder.DecodeType(ref signatureBlob));
            }
        }
Ejemplo n.º 4
0
        private static string GetGenericParametersSignature(MethodSpecification methodSpec, CilTypeProvider provider)
        {
            var           genericParameters = SignatureDecoder.DecodeMethodSpecificationSignature(methodSpec.Signature, provider);
            StringBuilder sb = new StringBuilder();
            int           i;

            for (i = 0; i < genericParameters.Length; i++)
            {
                if (i == 0)
                {
                    sb.Append("<");
                }
                sb.Append(genericParameters[i]);
                sb.Append(",");
            }
            if (i > 0)
            {
                sb.Length--;
                sb.Append(">");
            }
            return(sb.ToString());
        }