private void ThrowIfExportedValueIsNotAssignableToImport(RuntimeComposition.RuntimeImport import, RuntimeComposition.RuntimeExport export, object?exportedValue) { Requires.NotNull(import, nameof(import)); Requires.NotNull(export, nameof(export)); if (exportedValue != null) { if (!import.ImportingSiteTypeWithoutCollection.GetTypeInfo().IsAssignableFrom(exportedValue.GetType())) { throw new CompositionFailedException( string.Format( CultureInfo.CurrentCulture, Strings.ExportedValueNotAssignableToImport, RuntimeComposition.GetDiagnosticLocation(export), RuntimeComposition.GetDiagnosticLocation(import))); } } }
protected override void SatisfyImports() { if (this.Value == null && this.partDefinition.ImportingMembers.Count > 0) { // The value should have been instantiated by now. If it hasn't been, // it's not an instantiable part. And such a part cannot have imports set. this.ThrowPartNotInstantiableException(); } try { foreach (var import in this.partDefinition.ImportingMembers) { try { ValueForImportSite value = this.OwningExportProvider.GetValueForImportSite(this, import); if (value.ValueShouldBeSet) { SetImportingMember(this.Value !, import.ImportingMember !, value.Value); } } catch (CompositionFailedException ex) { throw new CompositionFailedException( string.Format( CultureInfo.CurrentCulture, Strings.ErrorWhileSettingImport, RuntimeComposition.GetDiagnosticLocation(import)), ex); } } } catch (TargetInvocationException ex) { throw this.PrepareExceptionForFaultedPart(ex); } }