コード例 #1
0
        private void PublicMethodNameMustBeUniqueInTargetClass(DelegateValidationRule <MethodIntroductionDefinition> .Args args)
        {
            if (args.Definition.Visibility == MemberVisibility.Public)
            {
                MethodInfo introducedMethod = args.Definition.InterfaceMember;

                var targetMethodsWithSameNameAndSignature = from candidate in _memberLookupUtility.GetCachedMembersByName(
                    args.Log.ContextStore,
                    args.Definition.DeclaringInterface.TargetClass,
                    introducedMethod.Name)
                                                            where _signatureComparer.Equals(candidate.MethodInfo, introducedMethod)
                                                            select candidate;
                if (targetMethodsWithSameNameAndSignature.Any())
                {
                    args.Log.Fail(args.Self);
                    return;
                }
            }

            args.Log.Succeed(args.Self);
        }
コード例 #2
0
        private MethodDefinition FindMethod(MethodInfo interfaceMethod, RequirementDefinitionBase requirement)
        {
            var candidatesByInheritanceOffset = from candidate in _allTargetMethodsByName[interfaceMethod.Name]
                                                where s_signatureComparer.Equals(candidate.MethodInfo, interfaceMethod)
                                                let offset = GetInheritanceOffset(candidate.MethodInfo.DeclaringType)
                                                             group candidate by offset;

            IGrouping <int, MethodDefinition> candidateGroup = ChooseCandidateGroup(candidatesByInheritanceOffset, interfaceMethod, requirement);

            // Unless the signature comparer is broken, each group can only hold one match.
            return(candidateGroup.Single());
        }
コード例 #3
0
        private TMember FindOverriddenMember(IOverrideAttribute attribute, TMember overrider)
        {
            var candidates = from candidate in BaseMembersByName[overrider.Name]
                             let candidateType = candidate.DeclaringClass.Type
                                                 where OverriddenMemberTypeMatches(candidateType, attribute.OverriddenType)
                                                 where s_signatureComparer.Equals(candidate.MemberInfo, overrider.MemberInfo)
                                                 select candidate;

            try
            {
                return(candidates.SingleOrDefault());
            }
            catch (InvalidOperationException)
            {
                string message = string.Format(
                    "Ambiguous override: Member '{0}' declared by type '{1}' could override any of the following: {2}.",
                    overrider.MemberInfo,
                    overrider.DeclaringClass.FullName,
                    BuildCandidateStringForExceptionMessage(candidates));
                throw new ConfigurationException(message);
            }
        }
コード例 #4
0
 public void Equals_Constructors_True()
 {
     Assert.That(_comparer.Equals(_c1, _c2), Is.True);
 }