protected override bool SpecificMatches(RoleCompositionMember member)
 {
     if (!(member.Definition is MethodDefinition)) return false; // non-methods are not grouped
       var controlMethod = Members[0];
       return MethodMatcher.IsSignatureMatch(
     (MethodDefinition)member.ResolveContextualDefinition(),
     (MethodDefinition)controlMethod.ResolveContextualDefinition());
 }
 /// <summary>
 /// Checks if a member matches the condition to be part of this conflict group.
 /// </summary>
 /// <remarks>
 /// The member will always match a group that it's already part of.
 /// For an empty group, the method <see cref="MatchesEmptyGroup"/> is called.
 /// The member won't match if it's a hidden member. Hidden members can't conflict with other members.
 /// The method <see cref="SpecificMatches"/> is called to check this group's condition.
 /// </remarks>
 /// <param name="member">Member to check for a match.</param>
 /// <returns>If the member matches this group's condition.</returns>
 public bool Matches(RoleCompositionMember member)
 {
     if (member == null) throw new ArgumentNullException("member");
       if (Members.Count == 0) return MatchesEmptyGroup(member);
       if (MemberMatcher.IsMatch(Members[0].ResolveContextualDefinition(), member.ResolveContextualDefinition())) return true;
       if (member.Definition.IsHidden(Module)) return false;
       return SpecificMatches(member);
 }
 /// <summary>
 /// Adds a member to this conflict group. It will fail if the member doesn't
 /// match the group's condition.
 /// </summary>
 /// <param name="member">Member to add to this group.</param>
 public void AddMember(RoleCompositionMember member)
 {
     if (member == null) throw new ArgumentNullException("member");
       if (Members.Contains(member)) return;
       // TODO: rename matches to accepts?
       if (!Matches(member)) throw new ArgumentException("member doesn't match group");
       Members.Add(member);
 }
 protected override bool MatchesEmptyGroup(RoleCompositionMember member)
 {
     return member.Definition is MethodDefinition;
 }
 protected override bool SpecificMatches(RoleCompositionMember member)
 {
     return member.Definition.Name == Members[0].Definition.Name;
 }
 public void SetUp()
 {
     var targetType = GetType<Class_With_Property>();
       _member = new RoleMember(targetType, targetType.Properties[0]);
       _group = new MethodSignatureConflictGroup();
 }
 private void AddRoleMember(TypeReference role, RoleCompositionMember member)
 {
     Container.AddMember(member);
 }
 protected override bool SpecificMatches(RoleCompositionMember member)
 {
     // TODO: other things that don't match anything: constructors?
       return MemberMatcher.IsMatch(Members[0].ResolveContextualDefinition(), member.ResolveContextualDefinition());
 }
 /// <summary>
 /// Runs the specific condition logic for this conflict group,
 /// to be defined by subclasses.
 /// </summary>
 /// <param name="member">Member to match.</param>
 /// <returns>If the member matches this group's condition.</returns>
 protected abstract bool SpecificMatches(RoleCompositionMember member);
示例#10
0
 /// <summary>
 /// Called to decide if a member can be part of an empty group, that is, 
 /// without considering other members. This is the initial condition for a
 /// member to be part of this group. By default returns <c>true</c>.
 /// </summary>
 /// <param name="member">Member to check.</param>
 /// <returns>If the member should be part of an empty group.</returns>
 protected virtual bool MatchesEmptyGroup(RoleCompositionMember member)
 {
     return true;
 }
示例#11
0
 private IMemberDefinition ImplementMember(string name, RoleCompositionMember roleMember, IEnumerable<RoleCompositionMember> overrides, MethodAttributes accessSpecifier)
 {
     _name = name;
       _roleMember = roleMember;
       _overrides = overrides;
       _accessSpecifier = accessSpecifier;
       return ImplementMember();
 }
示例#12
0
        private void ImplementBaseMethod(RoleCompositionMember typeMember, IEnumerable<RoleCompositionMember> overrides)
        {
            Tracer.TraceVerbose("Implement base method: {0}", typeMember.Definition);

              string baseMethodName = NameProvider.GetOriginalBaseMethodName(typeMember.Definition.Name);
              ClassMember baseMember = null;
              var currentType = TargetType.BaseType;
              do {
            var finder = new MemberFinder(currentType.Resolve());
            var foundBase = finder.FindMatchFor(typeMember.Definition, baseMethodName);
            if (foundBase != null) {
              baseMember = new ClassMember(currentType, foundBase, isInherited: true);
              break;
            }
            currentType = currentType.Resolve().BaseType;
              } while (currentType != null);
              if (baseMember == null) throw new InvalidOperationException();

              // TODO: refactor with AdjustSupercedingMember!
              var method = (MethodDefinition)typeMember.Definition;
              var targetMethod = new MemberResolver(baseMember.Class, Module).ResolveMethodDefinition(method, method.Name, MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.HideBySig);
              CreateCodeToCallBaseClassMethod(targetMethod, baseMember);
              TargetType.Methods.Add(targetMethod);
              AddOverrides(targetMethod, overrides);
        }