private bool SkipThisTypeDueToMismatchInReferenceAssemblyPlatform(AssemblyNode ultimateTargetAssembly, TypeNode typeNode) { if (ultimateTargetAssembly == null) return false; if (typeNode == this.contractNodes.ContractClass) return false; // don't skip contract methods as we need to extract their contracts if (HelperMethods.IsCompilerGenerated(typeNode)) return false; // don't skip closures etc. var typeWithSeparateContractClass = HelperMethods.IsContractTypeForSomeOtherTypeUnspecialized(typeNode, this.contractNodes); if (typeWithSeparateContractClass != null) { typeNode = typeWithSeparateContractClass; // see if this one is skipped } // now see if we have corresponding target type if (typeNode.FindShadow(ultimateTargetAssembly) != null) return false; // have target return true; // skip it. }
/// <summary> /// Returns the method implemented or overridden by the contractClass corresponding to the abstract method. /// /// Can't use TypeNode.GetImplementingMethod because the Reader creates the names of explicit /// interface methods such that it doesn't return them: it returns only implicit interface /// implementations. A contract class should never have both implicit and explicit /// implementations, so this just looks for an implicit first, then an explicit if that fails. /// </summary> /// <param name="contractClass">A class holding the contracts for an interface.</param> /// <param name="interfaceMethod">A method from that interface.</param> /// <returns>The method in the class that implements the interface method. </returns> internal static Method GetImplementation(TypeNode contractClass, Method abstractMethod) { Method m = contractClass.FindShadow(abstractMethod); if (m != null) // implicit implementation return m; if (abstractMethod.DeclaringType is Interface) { foreach (Member mem in contractClass.Members) { m = mem as Method; if (m == null || m.ImplementedInterfaceMethods == null) continue; foreach (Method ifaceMethod in m.ImplementedInterfaceMethods) { if (ifaceMethod == null) continue; if (ifaceMethod == abstractMethod || ifaceMethod.Template == abstractMethod) return m; // explicit implementation if (ifaceMethod.Template != null && ifaceMethod.Template == abstractMethod.Template) { return m; } } } } return null; }
public override void VisitTypeNode(TypeNode typeNode) { if (typeNode == null) return; // we might have copied this type already if (this.duplicatedMembers[typeNode.UniqueKey] != null) { return; } TypeNode targetType = typeNode.FindShadow(this.targetAssembly); if (targetType != null) { if (targetType.Contract == null) { targetType.Contract = new TypeContract(targetType, true); } this.outOfBandDuplicator.TargetType = targetType; if (typeNode.Contract != null) { InvariantList duplicatedInvariants = this.outOfBandDuplicator.VisitInvariantList(typeNode.Contract.Invariants); targetType.Contract.Invariants = duplicatedInvariants; } CopyAttributesWithoutDuplicateUnlessAllowMultiple(targetType, typeNode); base.VisitTypeNode(typeNode); } else { // target type does not exist. Copy it if (typeNode.DeclaringType != null) { // nested types are members and have been handled by CopyMissingMembers } else { this.outOfBandDuplicator.VisitTypeNode(typeNode); } } }