Beispiel #1
0
        private ExportCardinalityCheckResult TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, out IEnumerable <Export> exports)
        {
            Assumes.NotNull(definition);

            exports = GetExportsCore(definition, atomicComposition);

            var checkResult = ExportServices.CheckCardinality(definition, exports);

            // Export providers treat >1 match as zero for cardinality 0-1 imports
            // If this policy is moved we need to revisit the assumption that the
            // ImportEngine made during previewing the only required imports to
            // now also preview optional imports.
            if (checkResult == ExportCardinalityCheckResult.TooManyExports &&
                definition.Cardinality == ImportCardinality.ZeroOrOne)
            {
                checkResult = ExportCardinalityCheckResult.Match;
                exports     = null;
            }

            if (exports == null)
            {
                exports = EmptyExports;
            }

            return(checkResult);
        }
Beispiel #2
0
        private static void EnsureCardinality(ImportDefinition definition, Export[] exports)
        {
            Requires.NullOrNotNullElements(exports, "exports");

            ExportCardinalityCheckResult result = ExportServices.CheckCardinality(definition, exports);

            switch (result)
            {
            case ExportCardinalityCheckResult.NoExports:
                throw new ArgumentException(Strings.Argument_ExportsEmpty, "exports");

            case ExportCardinalityCheckResult.TooManyExports:
                throw new ArgumentException(Strings.Argument_ExportsTooMany, "exports");

            default:
                Assumes.IsTrue(result == ExportCardinalityCheckResult.Match);
                break;
            }
        }
        private static void EnsureCardinality(ImportDefinition definition, Export[] exports)
        {
            Requires.NullOrNotNullElements(exports, nameof(exports));

            ExportCardinalityCheckResult result = ExportServices.CheckCardinality(definition, exports);

            switch (result)
            {
            case ExportCardinalityCheckResult.NoExports:
                throw new ArgumentException(SR.Argument_ExportsEmpty, nameof(exports));

            case ExportCardinalityCheckResult.TooManyExports:
                throw new ArgumentException(SR.Argument_ExportsTooMany, nameof(exports));

            default:
                if (result != ExportCardinalityCheckResult.Match)
                {
                    throw new Exception(SR.Diagnostic_InternalExceptionMessage);
                }
                break;
            }
        }