Inheritance: MemberSignature
示例#1
0
        public static new MethodSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            if (!reader.CanRead(sizeof (byte)))
                return null;

            var signature = new MethodSignature
            {
                StartOffset = reader.Position,
                Attributes = (CallingConventionAttributes)reader.ReadByte()
            };

            if (signature.IsGeneric)
            {
                uint genericParameterCount;
                if (!reader.TryReadCompressedUInt32(out genericParameterCount))
                    return signature;
                signature.GenericParameterCount = (int)genericParameterCount;
            }

            uint parameterCount;
            if (!reader.TryReadCompressedUInt32(out parameterCount))
                return signature;

            signature.ReturnType = TypeSignature.FromReader(header, reader);
            for (int i = 0; i < parameterCount; i++)
            {
                signature.Parameters.Add(ParameterSignature.FromReader(header, reader));
            }

            return signature;
        }
 public FunctionPointerTypeSignature(MethodSignature signature)
 {
     Signature = signature;
 }
示例#3
0
        public MethodSignature ImportMethodSignature(MethodSignature signature)
        {
            var newSignature = new MethodSignature(ImportTypeSignature(signature.ReturnType))
            {
                Attributes = signature.Attributes,
                GenericParameterCount = signature.GenericParameterCount,
            };

            foreach (var parameter in signature.Parameters)
                newSignature.Parameters.Add(new ParameterSignature(ImportTypeSignature(parameter.ParameterType)));

            return newSignature;
        }
示例#4
0
        public MemberReference ImportMethod(MethodBase method)
        {
            // TODO: support generic instance methods.
            if (method.IsGenericMethod)
                throw new NotSupportedException();

            var returnType = method.IsConstructor ? typeof(void) : ((MethodInfo) method).ReturnType;
            var signature = new MethodSignature(ImportTypeSignature(returnType));

            if (!method.IsStatic)
                signature.Attributes |= CallingConventionAttributes.HasThis;

            foreach (var parameter in method.GetParameters())
            {
                signature.Parameters.Add(
                    new ParameterSignature(ImportTypeSignature(parameter.ParameterType)));
            }

            var reference = new MemberReference(ImportType(method.DeclaringType), method.Name, signature);
            return ImportMember(reference);
        }
示例#5
0
        /// <summary>
        /// Determines whether two method signatures are considered equal according to their signatures.
        /// </summary>
        /// <param name="signature1">The first signature to compare.</param>
        /// <param name="signature2">The second signature to compare.</param>
        /// <returns><c>True</c> if the signatures are considered equal, <c>False</c> otherwise.</returns>
        public bool MatchMethodSignatures(MethodSignature signature1, MethodSignature signature2)
        {
            if (signature1 == null && signature2 == null)
                return true;
            if (signature1 == null || signature2 == null)
                return false;

            return signature1.Attributes == signature2.Attributes &&
                   signature1.GenericParameterCount == signature2.GenericParameterCount &&
                   MatchTypes(signature1.ReturnType, signature2.ReturnType) &&
                   MatchManyTypes(signature1.Parameters.Select(x => x.ParameterType),
                       signature2.Parameters.Select(x => x.ParameterType));
        }
        public void MatchMethodSignatures()
        {
            var expected = new MethodSignature(new[] { CreateTypeSig1(), CreateTypeSig2() }, CreateTypeSig3());
            var match = new MethodSignature(new[] { CreateTypeSig1(), CreateTypeSig2() }, CreateTypeSig3());
            var fail1 = new MethodSignature(new TypeSignature[0], CreateTypeSig3());
            var fail2 = new MethodSignature(new[] { CreateTypeSig2(), CreateTypeSig1() }, CreateTypeSig3());
            var fail3 = new MethodSignature(new[] { CreateTypeSig2(), CreateTypeSig1() }, CreateTypeSig3());
            var fail4 = new MethodSignature(new[] { CreateTypeSig1(), CreateTypeSig2() }, CreateTypeSig3()) { HasThis = true };

            VerifyMatching(expected, match, fail1, fail2, fail3, fail4);
        }
示例#7
0
 public FunctionPointerTypeSignature(MethodSignature signature)
 {
     Signature = signature;
 }
示例#8
0
 public static void ValidateMethodSignature(MethodSignature originalSignature, MethodSignature newSignature)
 {
     ValidateType(originalSignature.ReturnType, newSignature.ReturnType);
     Assert.AreEqual(originalSignature.Attributes, newSignature.Attributes);
     Assert.AreEqual(originalSignature.Parameters.Count, newSignature.Parameters.Count);
     for (int i = 0; i < originalSignature.Parameters.Count; i++)
     {
         ValidateType(originalSignature.Parameters[i].ParameterType,
             newSignature.Parameters[i].ParameterType);
     }
 }