Beispiel #1
0
		private static bool SignatureMatches (MethodReference method, MethodReference baseMethod, bool explicitInterfaceCheck)
		{
			string name = method.Name;
			string base_name = baseMethod.Name;

			if (name != base_name) {
				if (!explicitInterfaceCheck)
					return false;

				TypeReference btype = baseMethod.DeclaringType;
				string bnspace = btype.Namespace;
				if (!name.StartsWith (bnspace, StringComparison.Ordinal))
					return false;
				if (name [bnspace.Length] != '.')
					return false;

				string bname = btype.Name;
				if (String.CompareOrdinal (bname, 0, name, bnspace.Length + 1, bname.Length) != 0)
					return false;

				int dot = bnspace.Length + bname.Length + 1;
				if (name [dot] != '.')
					return false;

				if (name.LastIndexOf (base_name, StringComparison.Ordinal) != dot + 1)
					return false;
			}
			return method.CompareSignature (baseMethod);
		}
Beispiel #2
0
        private static bool CompareMethods(MethodReference method1, MethodReference method2, bool virtual_call)
        {
            if (method1 == null)
            {
                return(method2 == null);
            }
            if (method2 == null)
            {
                return(false);
            }

            // shortcut, if it's not virtual then only compare metadata tokens
            if (!virtual_call)
            {
                return(method1.MetadataToken == method2.MetadataToken);
            }

            // we could be implementing an interface (skip position 0 because of .ctor and .cctor)
            string m1name             = method1.Name;
            bool   explicit_interface = (m1name.IndexOf('.') > 0);

            if (!explicit_interface && (m1name != method2.Name))
            {
                return(false);
            }

            // compare parameters
            if (!method1.CompareSignature(method2))
            {
                return(false);
            }

            TypeReference  t2  = method2.DeclaringType;
            TypeDefinition t2r = t2.Resolve();

            if (!explicit_interface && (t2r != null) && !t2r.IsInterface)
            {
                return(true);
            }

            // we're calling into an interface and this could be us!
            foreach (MethodReference mr in method1.Resolve().Overrides)
            {
                if (mr.DeclaringType.IsNamed(t2.Namespace, t2.Name))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
        static bool IsBase(MethodReference method, MethodReference mr)
        {
            if (mr.Name != method.Name)
            {
                return(false);
            }

            if (!mr.CompareSignature(method))
            {
                return(false);
            }

            TypeReference type = mr.DeclaringType;

            foreach (TypeDefinition baseType in method.DeclaringType.AllSuperTypes())
            {
                if (baseType.IsNamed(type.Namespace, type.Name))
                {
                    return(true);
                }
            }
            return(false);
        }