Ejemplo n.º 1
0
        private static Method FindInheritedMethod(Class baseClass, Method interfaceMethod)
        {
            while (baseClass != null)
            {
                if (InterfaceListContains(baseClass.Interfaces, interfaceMethod.DeclaringType))
                {
                    // instrumented in base
                    return null;
                }

                var candidate = baseClass.GetExactMatchingMethod(interfaceMethod);
                
                if (candidate != null) return candidate;
            
                baseClass = baseClass.BaseClass;
            }

            return null;
        }
Ejemplo n.º 2
0
        private void CheckForWrapperImplementationsForInheritedInterfaceImplementations(Class Class, Interface intf)
        {
            Contract.Requires(Class != null);
            Contract.Requires(intf != null);

            var members = intf.Members;
            // if (members == null) return;
            for (int i = 0; i < members.Count; i++)
            {
                var intfMethod = members[i] as Method;
                if (intfMethod == null) continue;

                if (Class.ExplicitImplementation(intfMethod) != null) continue;

                if (Class.GetExactMatchingMethod(intfMethod) != null) continue;

                var contractMethod = HelperMethods.GetContractMethod(intfMethod);
                if (contractMethod == null) continue;

                var contract = contractMethod.Contract;
                if (contract == null) continue;
                
                if (contract.RequiresCount + contract.EnsuresCount == 0) continue;

                // find base implementing method
                var baseMethod = FindInheritedMethod(Class.BaseClass, intfMethod);
                if (baseMethod == null) continue;
                
                var baseMethodImplementsInterfaceMethod = false;
                if (baseMethod.ImplicitlyImplementedInterfaceMethods != null)
                {
                    for (int j = 0; j < baseMethod.ImplicitlyImplementedInterfaceMethods.Count; j++)
                    {
                        if (baseMethod.ImplicitlyImplementedInterfaceMethods[j] == intfMethod)
                        {
                            baseMethodImplementsInterfaceMethod = true;
                            break;
                        }
                    }
                }

                if (baseMethodImplementsInterfaceMethod) continue;

                if (this.runtimeCheckingLevel < 3 && contract.RequiresCount == 0) continue;

                if (this.addInterfaceWrappersWhenNeeded)
                {
                    AddInterfaceImplementationWrapper(Class, intfMethod, baseMethod);
                }
                else
                {
                    this.HandleError(new Warning(1080,
                        string.Format(
                            "Type {0} implements {1} by inheriting {2} causing the interface contract to not be checked at runtime. Consider adding a wrapper method.",
                            Class.FullName, intfMethod.FullName, baseMethod.FullName),
                        default(SourceContext)));
                }
            }
        }