private static SerializableImportDefinition CreateConstructorParameterImport( ContractBasedImportDefinition import, Func <Type, TypeIdentity> identityGenerator) { var parameterInfo = ReflectionModelServices.GetImportingParameter(import); var requiredType = ExtractRequiredType(parameterInfo.Value.GetCustomAttributes(), parameterInfo.Value.ParameterType); if (requiredType == null) { return(null); } return(ConstructorBasedImportDefinition.CreateDefinition( import.ContractName, TypeIdentity.CreateDefinition(requiredType), import.Cardinality, import.RequiredCreationPolicy, parameterInfo.Value, identityGenerator)); }
private static GroupDefinition CreateImportingDefinition() { var groupName = "Import"; return(new GroupDefinition(groupName) { InternalConnections = Enumerable.Empty <PartImportToPartExportMap>(), Parts = new List <GroupPartDefinition> { new GroupPartDefinition( TypeIdentity.CreateDefinition(typeof(List <string>)), 0, new Dictionary <ExportRegistrationId, SerializableExportDefinition>(), new Dictionary <ImportRegistrationId, SerializableImportDefinition> { { new ImportRegistrationId(typeof(string), 0, "PartContract1"), PropertyBasedImportDefinition.CreateDefinition( "PartContract1", TypeIdentity.CreateDefinition(typeof(int)), ImportCardinality.ExactlyOne, false, CreationPolicy.Any, typeof(ImportOnPropertyWithType).GetProperty("ImportingProperty")) } }, new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(), new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()), new GroupPartDefinition( TypeIdentity.CreateDefinition(typeof(List <double>)), 1, new Dictionary <ExportRegistrationId, SerializableExportDefinition>(), new Dictionary <ImportRegistrationId, SerializableImportDefinition> { { new ImportRegistrationId(typeof(string), 1, "PartContract2"), ConstructorBasedImportDefinition.CreateDefinition( "PartContract2", TypeIdentity.CreateDefinition(typeof(string)), ImportCardinality.ExactlyOne, CreationPolicy.Any, typeof(Version).GetConstructor( new[] { typeof(string) }).GetParameters().First()) } }, new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(), new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()), }, GroupImports = new List <GroupImportDefinition> { GroupImportDefinition.CreateDefinition( "ContractName", new GroupRegistrationId(groupName), null, new List <ImportRegistrationId> { new ImportRegistrationId(typeof(string), 0, "PartContract1"), new ImportRegistrationId(typeof(string), 1, "PartContract2"), }) }, }); }