Esempio n. 1
0
        public bool ReturnTypesMatch(IMethodDefinition implMethod, IMethodDefinition contractMethod)
        {
            ITypeReference implType     = implMethod.GetReturnType();
            ITypeReference contractType = contractMethod.GetReturnType();

            if (implType == null || contractType == null)
            {
                return(true);
            }

            if (!_typeComparer.Equals(implType, contractType))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private bool ReturnTypesMatch(IDifferences differences, IMethodDefinition implMethod, IMethodDefinition contractMethod)
        {
            ITypeReference implReturnType = implMethod.GetReturnType();
            ITypeReference contractReturnType = contractMethod.GetReturnType();

            if (implReturnType == null || contractReturnType == null)
                return true;

            if (!_typeComparer.Equals(implReturnType, contractReturnType))
            {
                differences.AddTypeMismatchDifference("DelegateReturnTypesMustMatch", implReturnType, contractReturnType,
                    "Return type on delegate '{0}' is '{1}' in the implementation but '{2}' in the contract.",
                    implMethod.ContainingType.FullName(), implReturnType.FullName(), contractReturnType.FullName());
                return false;
            }

            return true;
        }
Esempio n. 3
0
        private bool ReturnTypesMatch(IDifferences differences, IMethodDefinition implMethod, IMethodDefinition contractMethod)
        {
            ITypeReference implReturnType     = implMethod.GetReturnType();
            ITypeReference contractReturnType = contractMethod.GetReturnType();

            if (implReturnType == null || contractReturnType == null)
            {
                return(true);
            }

            if (!_typeComparer.Equals(implReturnType, contractReturnType))
            {
                differences.AddTypeMismatchDifference("DelegateReturnTypesMustMatch", implReturnType, contractReturnType,
                                                      $"Return type on delegate '{implMethod.ContainingType.FullName()}' is '{implReturnType.FullName()}' in the {Implementation} but '{contractReturnType.FullName()}' in the {Contract}.");
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        public override DifferenceType Diff(IDifferences differences, MemberMapping mapping)
        {
            ITypeDefinitionMember implMember     = mapping[0];
            ITypeDefinitionMember contractMember = mapping[1];
            IMethodDefinition     foundMethod;

            if (!(implMember == null && contractMember != null))
            {
                return(DifferenceType.Unknown);
            }

            // Nested types are handled separately.
            // @TODO: Events and Properties - should we consider these too (or rely on the fact that dropping one of these will also drop their accessors.)
            if (!(contractMember is IMethodDefinition || contractMember is IFieldDefinition))
            {
                return(DifferenceType.Unknown);
            }

            string incompatibeDifferenceMessage = $"Member '{contractMember.FullName()}' does not exist in the {Implementation} but it does exist in the {Contract}.";

            ITypeDefinition contractType = mapping.ContainingType[0];

            if (contractType != null)
            {
                IMethodDefinition contractMethod = contractMember as IMethodDefinition;
                if (contractMethod != null)
                {
                    // If the contract is a Explicit Interface method, we don't need to check if the method is in implementation since that will be caught by different rule.
                    if (contractMethod.IsExplicitInterfaceMethod())
                    {
                        return(DifferenceType.Unknown);
                    }



                    // It is valid to promote a member from a base type up so check to see if it member exits on a base type.
                    var lookForMethodInBaseResult = FindMatchingBase(contractType, contractMethod, out foundMethod);
                    if (lookForMethodInBaseResult == FindMethodResult.Found)
                    {
                        return(DifferenceType.Unknown);
                    }
                    if (lookForMethodInBaseResult == FindMethodResult.ReturnTypeChanged)
                    {
                        incompatibeDifferenceMessage += $" There does exist a member with return type '{foundMethod.GetReturnType().FullName()}' instead of '{contractMethod.GetReturnType().FullName()}'";
                    }
                }
            }

            differences.AddIncompatibleDifference(this, incompatibeDifferenceMessage);

            return(DifferenceType.Added);
        }
Esempio n. 5
0
        public bool ReturnTypesMatch(IMethodDefinition implMethod, IMethodDefinition contractMethod)
        {
            ITypeReference implType = implMethod.GetReturnType();
            ITypeReference contractType = contractMethod.GetReturnType();

            if (implType == null || contractType == null)
                return true;

            if (!_typeComparer.Equals(implType, contractType))
            {
                return false;
            }

            return true;
        }