Пример #1
0
        private static ExportInfo[] GetExportsFromExportManyAttribute(ExportedRegistrationInfo currentInfo,
                                                                      Type implementationType, ExportManyAttribute exportManyAttribute)
        {
            var contractTypes = Registrator.GetImplementedServiceTypes(implementationType, exportManyAttribute.NonPublic);

            if (!exportManyAttribute.Except.IsNullOrEmpty())
            {
                contractTypes = contractTypes.Except(exportManyAttribute.Except).ToArrayOrSelf();
            }

            var manyExports = contractTypes
                              .Select(t => new ExportInfo(t, exportManyAttribute.ContractName ?? exportManyAttribute.ContractKey))
                              .ToArray();

            Throw.If(manyExports.Length == 0, Error.ExportManyDoesNotExportAnyType, implementationType, contractTypes);

            var currentExports = currentInfo.Exports;

            if (!currentExports.IsNullOrEmpty())
            {
                for (var i = 0; i < currentExports.Length; i++)
                {
                    if (!manyExports.Contains(currentExports[i]))
                    {
                        manyExports = manyExports.AppendOrUpdate(currentExports[i]);
                    }
                }
            }

            return(manyExports);
        }