/// <summary> /// Returns all exports that match the conditions of the specified import. /// </summary> /// <param name="definition"> /// The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="Export"/> objects to get. /// </param> /// <param name="atomicComposition">The transactional container for the composition.</param> /// <param name="exports"> /// When this method returns, contains an <see cref="IEnumerable{T}"/> of <see cref="Export"/> /// objects that match the conditions defined by <see cref="ImportDefinition"/>, if found; /// otherwise, an empty <see cref="IEnumerable{T}"/>. /// </param> /// <returns> /// <see langword="true"/> if <see cref="ImportDefinition.Cardinality"/> is /// <see cref="ImportCardinality.ZeroOrOne"/> or <see cref="ImportCardinality.ZeroOrMore"/> and /// there are zero <see cref="Export"/> objects that match the conditions of the specified /// <see cref="ImportDefinition"/>. <see langword="true"/> if /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or /// <see cref="ImportCardinality.ExactlyOne"/> and there is exactly one <see cref="Export"/> /// that matches the conditions of the specified <see cref="ImportDefinition"/>; otherwise, /// <see langword="false"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> public bool TryGetExports(ImportDefinition definition, AtomicComposition?atomicComposition, out IEnumerable <Export>?exports) { Requires.NotNull(definition, nameof(definition)); ExportCardinalityCheckResult result = TryGetExportsCore(definition, atomicComposition, out exports); return(result == ExportCardinalityCheckResult.Match); }
/// <summary> /// Returns all exports that match the conditions of the specified import. /// </summary> /// <param name="definition"> /// The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="Export"/> objects to get. /// </param> /// <param name="exports"> /// When this method returns, contains an <see cref="IEnumerable{T}"/> of <see cref="Export"/> /// objects that match the conditions defined by <see cref="ImportDefinition"/>, if found; /// otherwise, an empty <see cref="IEnumerable{T}"/>. /// </param> /// <returns> /// <see langword="true"/> if <see cref="ImportDefinition.Cardinality"/> is /// <see cref="ImportCardinality.ZeroOrOne"/> or <see cref="ImportCardinality.ZeroOrMore"/> and /// there are zero <see cref="Export"/> objects that match the conditions of the specified /// <see cref="ImportDefinition"/>. <see langword="true"/> if /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or /// <see cref="ImportCardinality.ExactlyOne"/> and there is exactly one <see cref="Export"/> /// that matches the conditions of the specified <see cref="ImportDefinition"/>; otherwise, /// <see langword="false"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> public bool TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, out IEnumerable<Export> exports) { Requires.NotNull(definition, "definition"); exports = null; ExportCardinalityCheckResult result = this.TryGetExportsCore(definition, atomicComposition, out exports); return (result == ExportCardinalityCheckResult.Match); }
/// <summary> /// Returns all exports that match the conditions of the specified import. /// </summary> /// <param name="definition"> /// The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="Export"/> objects to get. /// </param> /// <result> /// An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects that match /// the conditions defined by <see cref="ImportDefinition"/>, if found; otherwise, an /// empty <see cref="IEnumerable{T}"/>. /// </result> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> /// <exception cref="ImportCardinalityMismatchException"> /// <para> /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ExactlyOne"/> and /// there are zero <see cref="Export"/> objects that match the conditions of the specified /// <see cref="ImportDefinition"/>. /// </para> /// -or- /// <para> /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or /// <see cref="ImportCardinality.ExactlyOne"/> and there are more than one <see cref="Export"/> /// objects that match the conditions of the specified <see cref="ImportDefinition"/>. /// </para> /// </exception> public IEnumerable<Export> GetExports(ImportDefinition definition, AtomicComposition atomicComposition) { Requires.NotNull(definition, "definition"); Contract.Ensures(Contract.Result<IEnumerable<Export>>() != null); IEnumerable<Export> exports; ExportCardinalityCheckResult result = this.TryGetExportsCore(definition, atomicComposition, out exports); switch(result) { case ExportCardinalityCheckResult.Match: return exports; case ExportCardinalityCheckResult.NoExports: throw new ImportCardinalityMismatchException(string.Format(CultureInfo.CurrentCulture, Strings.CardinalityMismatch_NoExports, definition.Constraint.Body.ToString())); default: Assumes.IsTrue(result == ExportCardinalityCheckResult.TooManyExports); throw new ImportCardinalityMismatchException(string.Format(CultureInfo.CurrentCulture, Strings.CardinalityMismatch_TooManyExports, definition.Constraint.Body.ToString())); } }
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; } }
/// <summary> /// Returns all exports that match the conditions of the specified import. /// </summary> /// <param name="definition"> /// The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="Export"/> objects to get. /// </param> /// <param name="atomicComposition">The transactional container for the composition.</param> /// <result> /// An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects that match /// the conditions defined by <see cref="ImportDefinition"/>, if found; otherwise, an /// empty <see cref="IEnumerable{T}"/>. /// </result> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> /// <exception cref="ImportCardinalityMismatchException"> /// <para> /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ExactlyOne"/> and /// there are zero <see cref="Export"/> objects that match the conditions of the specified /// <see cref="ImportDefinition"/>. /// </para> /// -or- /// <para> /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or /// <see cref="ImportCardinality.ExactlyOne"/> and there are more than one <see cref="Export"/> /// objects that match the conditions of the specified <see cref="ImportDefinition"/>. /// </para> /// </exception> public IEnumerable <Export> GetExports(ImportDefinition definition, AtomicComposition?atomicComposition) { Requires.NotNull(definition, nameof(definition)); ExportCardinalityCheckResult result = TryGetExportsCore(definition, atomicComposition, out IEnumerable <Export>?exports); switch (result) { case ExportCardinalityCheckResult.Match: Debug.Assert(exports != null); return(exports); case ExportCardinalityCheckResult.NoExports: throw new ImportCardinalityMismatchException(SR.Format(SR.CardinalityMismatch_NoExports, definition)); default: if (result != ExportCardinalityCheckResult.TooManyExports) { throw new Exception(SR.Diagnostic_InternalExceptionMessage); } throw new ImportCardinalityMismatchException(SR.Format(SR.CardinalityMismatch_TooManyExports_Constraint, definition)); } }
/// <summary> /// Returns all exports that match the conditions of the specified import. /// </summary> /// <param name="definition"> /// The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="Export"/> objects to get. /// </param> /// <result> /// An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects that match /// the conditions defined by <see cref="ImportDefinition"/>, if found; otherwise, an /// empty <see cref="IEnumerable{T}"/>. /// </result> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> /// <exception cref="ImportCardinalityMismatchException"> /// <para> /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ExactlyOne"/> and /// there are zero <see cref="Export"/> objects that match the conditions of the specified /// <see cref="ImportDefinition"/>. /// </para> /// -or- /// <para> /// <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or /// <see cref="ImportCardinality.ExactlyOne"/> and there are more than one <see cref="Export"/> /// objects that match the conditions of the specified <see cref="ImportDefinition"/>. /// </para> /// </exception> public IEnumerable <Export> GetExports(ImportDefinition definition, AtomicComposition atomicComposition) { Requires.NotNull(definition, nameof(definition)); Contract.Ensures(Contract.Result <IEnumerable <Export> >() != null); IEnumerable <Export> exports; ExportCardinalityCheckResult result = TryGetExportsCore(definition, atomicComposition, out exports); switch (result) { case ExportCardinalityCheckResult.Match: return(exports); case ExportCardinalityCheckResult.NoExports: throw new ImportCardinalityMismatchException(string.Format(CultureInfo.CurrentCulture, SR.CardinalityMismatch_NoExports, definition.ToString())); default: if (result != ExportCardinalityCheckResult.TooManyExports) { throw new Exception(SR.Diagnostic_InternalExceptionMessage); } throw new ImportCardinalityMismatchException(string.Format(CultureInfo.CurrentCulture, SR.CardinalityMismatch_TooManyExports_Constraint, definition.ToString())); } }