private static GroupDefinition CreateExportingGroup()
 {
     return(new GroupDefinition("a")
     {
         InternalConnections = Enumerable.Empty <PartImportToPartExportMap>(),
         Parts = new List <GroupPartDefinition>
         {
             new GroupPartDefinition(
                 TypeIdentity.CreateDefinition(typeof(int)),
                 0,
                 new Dictionary <ExportRegistrationId, SerializableExportDefinition>
             {
                 {
                     new ExportRegistrationId(typeof(int), 0, "PartContract1"),
                     TypeBasedExportDefinition.CreateDefinition("PartContract1", typeof(int))
                 }
             },
                 new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                 new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                 new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
             new GroupPartDefinition(
                 TypeIdentity.CreateDefinition(typeof(string)),
                 1,
                 new Dictionary <ExportRegistrationId, SerializableExportDefinition>
             {
                 {
                     new ExportRegistrationId(typeof(string), 1, "PartContract2"),
                     TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                 }
             },
                 new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                 new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                 new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
             new GroupPartDefinition(
                 TypeIdentity.CreateDefinition(typeof(Version)),
                 2,
                 new Dictionary <ExportRegistrationId, SerializableExportDefinition>
             {
                 {
                     new ExportRegistrationId(typeof(string), 2, "PartContract2"),
                     TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                 }
             },
                 new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                 new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                 new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
         },
         GroupExport = GroupExportDefinition.CreateDefinition(
             "ContractName",
             new GroupRegistrationId("a"),
             new List <ExportRegistrationId>
         {
             new ExportRegistrationId(typeof(int), 0, "PartContract1"),
             new ExportRegistrationId(typeof(string), 1, "PartContract2"),
             new ExportRegistrationId(typeof(string), 2, "PartContract2"),
         }),
     });
 }
 private static SerializableExportDefinition CreateTypeExport(
     ExportDefinition export,
     LazyMemberInfo memberInfo,
     Func <Type, TypeIdentity> identityGenerator)
 {
     Debug.Assert(memberInfo.GetAccessors().Count() == 1, "Only expecting one accessor for a type export.");
     Debug.Assert(memberInfo.GetAccessors().First() is Type, "Expecting the export to be a Type.");
     return(TypeBasedExportDefinition.CreateDefinition(
                export.ContractName,
                memberInfo.GetAccessors().First() as Type,
                identityGenerator));
 }
        private static GroupDefinition CreateExportingDefinition()
        {
            var groupName = "Export";

            return(new GroupDefinition(groupName)
            {
                Parts = new List <GroupPartDefinition>
                {
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(int)),
                        0,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(int), 0, "PartContract1"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract1", typeof(int))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(string)),
                        1,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(string), 1, "PartContract2"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(Version)),
                        2,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(string), 2, "PartContract2"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),

                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(DateTime)),
                        2,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(string), 3, "PartContract3"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract3", typeof(string))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(List <int>)),
                        2,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>(),
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>
                    {
                        {
                            new ImportRegistrationId(typeof(string), 1, "PartContract3"),
                            PropertyBasedImportDefinition.CreateDefinition(
                                "PartContract3",
                                TypeIdentity.CreateDefinition(typeof(string)),
                                ImportCardinality.ExactlyOne,
                                false,
                                CreationPolicy.Any,
                                typeof(ImportOnPropertyWithEnumerable).GetProperty("ImportingProperty"))
                        }
                    },
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                },
                InternalConnections = new List <PartImportToPartExportMap>
                {
                    new PartImportToPartExportMap(
                        new ImportRegistrationId(typeof(string), 1, "PartContract3"),
                        new List <ExportRegistrationId>
                    {
                        new ExportRegistrationId(typeof(string), 3, "PartContract3")
                    }),
                },
                GroupExport = GroupExportDefinition.CreateDefinition(
                    "ContractName",
                    new GroupRegistrationId(groupName),
                    new List <ExportRegistrationId>
                {
                    new ExportRegistrationId(typeof(int), 0, "PartContract1"),
                    new ExportRegistrationId(typeof(string), 1, "PartContract2"),
                    new ExportRegistrationId(typeof(string), 2, "PartContract2"),
                }),
            });
        }
        private static IEnumerable <PartDefinition> CreatePluginTypes()
        {
            var plugins = new List <PartDefinition>
            {
                new PartDefinition
                {
                    Identity = TypeIdentity.CreateDefinition(typeof(ActionOnMethod)),
                    Exports  = new List <SerializableExportDefinition>
                    {
                        TypeBasedExportDefinition.CreateDefinition("ActionExport", typeof(ActionOnMethod))
                    },
                    Imports = new List <SerializableImportDefinition>(),
                    Actions = new List <ScheduleActionDefinition>
                    {
                        ScheduleActionDefinition.CreateDefinition(
                            "ActionMethod",
                            typeof(ActionOnMethod).GetMethod("ActionMethod"))
                    },
                    Conditions = new List <ScheduleConditionDefinition>(),
                },
                new PartDefinition
                {
                    Identity = TypeIdentity.CreateDefinition(typeof(ConditionOnMethod)),
                    Exports  = new List <SerializableExportDefinition>
                    {
                        TypeBasedExportDefinition.CreateDefinition("ConditionOnMethodExport", typeof(ConditionOnMethod))
                    },
                    Imports    = new List <SerializableImportDefinition>(),
                    Actions    = new List <ScheduleActionDefinition>(),
                    Conditions = new List <ScheduleConditionDefinition>
                    {
                        MethodBasedScheduleConditionDefinition.CreateDefinition(
                            "OnMethod",
                            typeof(ConditionOnMethod).GetMethod("ConditionMethod"))
                    },
                },
                new PartDefinition
                {
                    Identity = TypeIdentity.CreateDefinition(typeof(ConditionOnProperty)),
                    Exports  = new List <SerializableExportDefinition>
                    {
                        TypeBasedExportDefinition.CreateDefinition("ConditionOnPropertyExport", typeof(ConditionOnProperty))
                    },
                    Imports    = new List <SerializableImportDefinition>(),
                    Actions    = new List <ScheduleActionDefinition>(),
                    Conditions = new List <ScheduleConditionDefinition>
                    {
                        PropertyBasedScheduleConditionDefinition.CreateDefinition(
                            "OnProperty",
                            typeof(ConditionOnProperty).GetProperty("ConditionProperty"))
                    },
                },
                new PartDefinition
                {
                    Identity = TypeIdentity.CreateDefinition(typeof(ExportOnProperty)),
                    Exports  = new List <SerializableExportDefinition>
                    {
                        PropertyBasedExportDefinition.CreateDefinition(
                            typeof(IExportingInterface).FullName,
                            typeof(ExportOnProperty).GetProperty("ExportingProperty"))
                    },
                    Imports    = new List <SerializableImportDefinition>(),
                    Actions    = new List <ScheduleActionDefinition>(),
                    Conditions = new List <ScheduleConditionDefinition>(),
                },
                new PartDefinition
                {
                    Identity = TypeIdentity.CreateDefinition(typeof(ImportOnProperty)),
                    Exports  = new List <SerializableExportDefinition>
                    {
                        TypeBasedExportDefinition.CreateDefinition(typeof(ImportOnProperty).FullName, typeof(ImportOnProperty))
                    },
                    Imports = new List <SerializableImportDefinition>
                    {
                        PropertyBasedImportDefinition.CreateDefinition(
                            typeof(IExportingInterface).FullName,
                            TypeIdentity.CreateDefinition(typeof(IExportingInterface)),
                            ImportCardinality.ExactlyOne,
                            false,
                            CreationPolicy.Shared,
                            typeof(ImportOnProperty).GetProperty("ImportingProperty"))
                    },
                    Actions    = new List <ScheduleActionDefinition>(),
                    Conditions = new List <ScheduleConditionDefinition>(),
                }
            };

            return(plugins);
        }