public bool Accepts(SerializableImportDefinition importDefinition, SerializableExportDefinition exportDefinition) { if (!string.Equals(importDefinition.ContractName, exportDefinition.ContractName, StringComparison.OrdinalIgnoreCase)) { return(false); } var importRequiredType = importDefinition.RequiredTypeIdentity; var importRequiredTypeDef = m_Repository.TypeByIdentity(importRequiredType); var exportType = ExportedType(exportDefinition); if (AvailableTypeMatchesRequiredType(importRequiredType, exportType)) { return(true); } Func <TypeIdentity, TypeDefinition> toDefinition = t => m_Repository.TypeByIdentity(t); if (importRequiredTypeDef.IsCollection(toDefinition) && ExportMatchesCollectionImport(importRequiredType, exportType, toDefinition)) { return(true); } if (importRequiredTypeDef.IsLazy(toDefinition) && ExportMatchesLazyImport(importRequiredType, exportType)) { return(true); } if (importRequiredTypeDef.IsFunc(toDefinition) && ExportMatchesFuncImport(importRequiredType, exportType, exportDefinition)) { return(true); } if (importRequiredTypeDef.IsAction(toDefinition) && ExportMatchesActionImport(importRequiredType, exportDefinition)) { return(true); } return(false); }
public bool Accepts(SerializableImportDefinition importDefinition, SerializableExportDefinition exportDefinition) { if (!string.Equals(importDefinition.ContractName, exportDefinition.ContractName, StringComparison.OrdinalIgnoreCase)) { return false; } var importRequiredType = importDefinition.RequiredTypeIdentity; var importRequiredTypeDef = m_Repository.TypeByIdentity(importRequiredType); var exportType = ExportedType(exportDefinition); if (AvailableTypeMatchesRequiredType(importRequiredType, exportType)) { return true; } Func<TypeIdentity, TypeDefinition> toDefinition = t => m_Repository.TypeByIdentity(t); if (importRequiredTypeDef.IsCollection(toDefinition) && ExportMatchesCollectionImport(importRequiredType, exportType, toDefinition)) { return true; } if (importRequiredTypeDef.IsLazy(toDefinition) && ExportMatchesLazyImport(importRequiredType, exportType)) { return true; } if (importRequiredTypeDef.IsFunc(toDefinition) && ExportMatchesFuncImport(importRequiredType, exportType, exportDefinition)) { return true; } if (importRequiredTypeDef.IsAction(toDefinition) && ExportMatchesActionImport(importRequiredType, exportDefinition)) { return true; } return false; }
public override bool Equals(SerializableImportDefinition other) { var otherType = other as ConstructorBasedImportDefinition; if (ReferenceEquals(this, other)) { return true; } // Check if other is a null reference by using ReferenceEquals because // we overload the == operator. If other isn't actually null then // we get an infinite loop where we're constantly trying to compare to null. return !ReferenceEquals(otherType, null) && string.Equals(ContractName, otherType.ContractName, StringComparison.OrdinalIgnoreCase) && RequiredTypeIdentity.Equals(otherType.RequiredTypeIdentity) && Constructor == otherType.Constructor && Parameter == otherType.Parameter; }
private IEnumerable <Tuple <Type, PartDefinition> > ExtractImportsAndExports(Assembly assembly, Func <Type, TypeIdentity> createTypeIdentity) { var catalog = new AssemblyCatalog(assembly); foreach (var part in catalog.Parts) { var exports = new List <SerializableExportDefinition>(); foreach (var export in part.ExportDefinitions) { var memberInfo = ReflectionModelServices.GetExportingMember(export); SerializableExportDefinition exportDefinition = null; switch (memberInfo.MemberType) { case MemberTypes.Method: exportDefinition = CreateMethodExport(export, memberInfo, createTypeIdentity); break; case MemberTypes.Property: exportDefinition = CreatePropertyExport(export, memberInfo, createTypeIdentity); break; case MemberTypes.NestedType: case MemberTypes.TypeInfo: exportDefinition = CreateTypeExport(export, memberInfo, createTypeIdentity); break; default: throw new NotImplementedException(); } if (exportDefinition != null) { exports.Add(exportDefinition); m_Logger.Log( LevelToLog.Info, string.Format( CultureInfo.InvariantCulture, "Discovered export: {0}", exportDefinition)); } else { m_Logger.Log( LevelToLog.Warn, string.Format( CultureInfo.InvariantCulture, "Unable to process export: {0} on a {1}", export.ContractName, memberInfo.MemberType)); } } var imports = new List <SerializableImportDefinition>(); foreach (var import in part.ImportDefinitions) { Debug.Assert(import is ContractBasedImportDefinition, "All import objects should be ContractBasedImportDefinition objects."); var contractImport = import as ContractBasedImportDefinition; SerializableImportDefinition importDefinition = !ReflectionModelServices.IsImportingParameter(contractImport) ? CreatePropertyImport(contractImport, createTypeIdentity) : CreateConstructorParameterImport(contractImport, createTypeIdentity); if (importDefinition != null) { imports.Add(importDefinition); m_Logger.Log( LevelToLog.Info, string.Format( CultureInfo.InvariantCulture, "Discovered import: {0}", importDefinition)); } else { m_Logger.Log( LevelToLog.Warn, string.Format( CultureInfo.InvariantCulture, "Unable to process import: {0}", import.ContractName)); } } var type = ReflectionModelServices.GetPartType(part).Value; yield return(new Tuple <Type, PartDefinition>( type, new PartDefinition { Identity = createTypeIdentity(type), Exports = exports, Imports = imports, Actions = Enumerable.Empty <ScheduleActionDefinition>(), Conditions = Enumerable.Empty <ScheduleConditionDefinition>(), })); } }