Ejemplo n.º 1
0
        private void SetImport(ImportingItem item, Export[] exports)
        {
            object value = item.CastExportsToImportType(exports);

            this._invokeImportsSatisfied        = true;
            this._importValues[item.Definition] = value;
        }
Ejemplo n.º 2
0
        private void SetExportedValueForImport(ImportingItem import, ImportDefinition definition, object value)
        {
            ImportingMember importMember = (ImportingMember)import;

            object instance = this.GetInstanceActivatingIfNeeded();

            importMember.SetExportedValue(instance, value);
        }
        private void SetImport(ImportingItem item, Export[] exports)
        {
            object?value = item.CastExportsToImportType(exports);

            lock (_lock)
            {
                _invokeImportsSatisfied       = true;
                ImportValues[item.Definition] = value;
            }
        }
Ejemplo n.º 4
0
        public override void SetImport(ImportDefinition definition, IEnumerable <Export> exports)
        {
            this.RequiresRunning();
            Requires.NotNull(definition, "definition");
            Requires.NotNull(exports, "exports");;

            ImportingItem item = GetImportingItemFromDefinition(definition);

            if (item == null)
            {
                throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart("definition");
            }

            EnsureSettable(definition);

            // Avoid walking over exports many times
            Export[] exportsAsArray = exports.AsArray();
            EnsureCardinality(definition, exportsAsArray);

            SetImport(item, exportsAsArray);
        }
Ejemplo n.º 5
0
        private void UseImportedValues <TImportDefinition>(IEnumerable <TImportDefinition> definitions, Action <ImportingItem, TImportDefinition, object> useImportValue, bool errorIfMissing)
            where TImportDefinition : ImportDefinition
        {
            var result = CompositionResult.SucceededResult;

            foreach (var definition in definitions)
            {
                ImportingItem import = GetImportingItemFromDefinition(definition);

                object value;
                if (!TryGetImportValue(definition, out value))
                {
                    if (!errorIfMissing)
                    {
                        continue;
                    }

                    if (definition.Cardinality == ImportCardinality.ExactlyOne)
                    {
                        var error = CompositionError.Create(
                            CompositionErrorId.ImportNotSetOnPart,
                            Strings.ImportNotSetOnPart,
                            this.Definition.GetPartType().FullName,
                            definition.ToString());
                        result = result.MergeError(error);
                        continue;
                    }
                    else
                    {
                        value = import.CastExportsToImportType(new Export[0]);
                    }
                }

                useImportValue(import, definition, value);
            }

            result.ThrowOnErrors();
        }