예제 #1
0
 /// <summary>
 /// Checks if at least one Method satisfies a given MethodSignature.
 /// </summary>
 /// <param name="self">The TypeReference on which the extension method can be called.</param>
 /// <param name="signature">The MethodSignature to match.</param>
 /// <returns>True if at least one method matches the signature. Otherwise false.</returns>
 public static bool HasMethod(this TypeReference self, MethodSignature signature)
 {
     return ((self != null) && self.GetMethod(signature) != null);
 }
예제 #2
0
        /// <summary>
        /// Returns the first MethodDefinition that satisfies a given MethodSignature.
        /// </summary>
        /// <param name="self">The TypeReference on which the extension method can be called.</param>
        /// <param name="signature">The MethodSignature to match.</param>
        /// <returns>The first MethodDefinition for wich signature.Matches returns true.</returns>
        /// <remarks>
        /// Do not allocate a MethodSignature for only one call. Use one of the other GetMethod overloads instead.
        /// </remarks>
        public static MethodDefinition GetMethod(this TypeReference self, MethodSignature signature)
        {
            if (signature == null)
                throw new ArgumentNullException("signature");
            if (self == null)
                return null;

            TypeDefinition type = self.Resolve();
            if (type == null)
                return null;

            if (type.HasMethods)
            {
                foreach (MethodDefinition method in type.Methods)
                {
                    if (signature.Matches(method))
                        return method;
                }
            }
            return null;
        }