public InterfaceMapping ComputeMapping( MutableType mutableType, Func <Type, InterfaceMapping> interfacMappingProvider, Type interfaceType, bool allowPartialInterfaceMapping) { ArgumentUtility.CheckNotNull("mutableType", mutableType); ArgumentUtility.CheckNotNull("interfacMappingProvider", interfacMappingProvider); ArgumentUtility.CheckNotNull("interfaceType", interfaceType); if (!interfaceType.IsInterface) { throw new ArgumentException("Type passed must be an interface.", "interfaceType"); } if (!mutableType.GetInterfaces().Contains(interfaceType)) { throw new ArgumentException("Interface not found.", "interfaceType"); } var mapping = mutableType.AddedInterfaces.Contains(interfaceType) ? CreateForAdded(mutableType, interfaceType) : CreateForExisting(mutableType, interfacMappingProvider, interfaceType); var targetMethods = mapping.TargetMethods; var interfaceMethods = mapping.InterfaceMethods; // Explicit implementations overrule implicit implementations. var explicitImplementations = mutableType.AddedMethods .SelectMany(m => m.AddedExplicitBaseDefinitions.Select(b => new { Base = b, Override = m })) .ToDictionary(t => t.Base, t => (MethodInfo)t.Override); for (int i = 0; i < targetMethods.Length; i++) { MethodInfo value; if (explicitImplementations.TryGetValue(interfaceMethods[i], out value)) { targetMethods[i] = value; } } if (targetMethods.Contains(null) && !allowPartialInterfaceMapping) { var missingMethods = interfaceMethods.Zip(targetMethods, Tuple.Create).Where(t => t.Item2 == null).Select(t => t.Item1); var message = string.Format( "The added interface '{0}' is not fully implemented. The following methods have no implementation: {1}.", interfaceType.Name, string.Join(", ", missingMethods.Select(m => "'" + m.Name + "'"))); throw new InvalidOperationException(message); } return(mapping); }
private bool IsIndependent(MutableType type, HashSet <MutableType> types) { return(!ContainsCycle(types, type.BaseType) && !type.GetInterfaces().Any(t => ContainsCycle(types, t))); }