本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionBatch.RemovePart方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionBatch.RemovePart方法的具体用法?C# CompositionBatch.RemovePart怎么用?C# CompositionBatch.RemovePart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionBatch
的用法示例。
在下文中一共展示了CompositionBatch.RemovePart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SingleContainerPartReplacement
public void SingleContainerPartReplacement()
{
var container = ContainerFactory.Create();
var importPart = PartFactory.CreateImporter(true, "value1", "value2");
CompositionBatch batch = new CompositionBatch();
var export1Key = batch.AddExportedValue("value1", "Hello");
batch.AddExportedValue("value2", "World");
batch.AddPart(importPart);
container.Compose(batch);
Assert.AreEqual(2, importPart.ImportSatisfiedCount);
Assert.AreEqual("Hello", importPart.GetImport("value1"));
Assert.AreEqual("World", importPart.GetImport("value2"));
importPart.ResetImportSatisfiedCount();
batch = new CompositionBatch();
batch.RemovePart(export1Key);
batch.AddExportedValue("value1", "Goodbye");
container.Compose(batch);
Assert.AreEqual(1, importPart.ImportSatisfiedCount);
Assert.AreEqual("Goodbye", importPart.GetImport("value1"));
Assert.AreEqual("World", importPart.GetImport("value2"));
}
示例2: ComposeBatchTwo
private static void ComposeBatchTwo(CompositionContainer container)
{
var batch = new CompositionBatch();
batch.RemovePart(a);
c = batch.AddPart(new PluginC());
batch.AddPart(logger);
container.Compose(batch);
}
示例3: BatchRemove_ShouldFireEvents
public void BatchRemove_ShouldFireEvents()
{
var container = ContainerFactory.Create();
var batch = new CompositionBatch();
var exportPart = batch.AddExportedValue<object>("MyExport", new object());
container.Compose(batch);
var eventListener = new ExportProviderListener(container, container);
batch = new CompositionBatch();
batch.RemovePart(exportPart);
eventListener.VerifyCompose(batch);
}
示例4: AddRemovePart_NonSharedPart_ShouldCollectWholeObjectChain
public void AddRemovePart_NonSharedPart_ShouldCollectWholeObjectChain()
{
var container = GetContainer();
var exportedValue = new NonSharedImporter();
CompositionBatch batch = new CompositionBatch();
var part = batch.AddPart(exportedValue);
container.Compose(batch);
batch = null;
batch = new CompositionBatch();
batch.RemovePart(part);
container.Compose(batch);
batch = null;
var refTracker = new ReferenceTracker();
refTracker.AddReferencesExpectedToBeCollected(
exportedValue,
exportedValue.AnyPartDisposable,
exportedValue.AnyPartDisposableRecomposable,
exportedValue.AnyPartRecomposable,
exportedValue.AnyPartSimple);
part = null;
exportedValue = null;
refTracker.CollectAndAssert();
GC.KeepAlive(container);
}
示例5: ImportIntoUntypedExportTest
public void ImportIntoUntypedExportTest()
{
var container = ContainerFactory.Create();
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue("untyped", 42);
var u = new UntypedExportImporter();
var rb = AttributedModelServices.CreatePart(u);
batch.AddPart(rb);
container.Compose(batch);
Assert.AreEqual(42, u.Export.Value);
var us = new UntypedExportsImporter();
batch = new CompositionBatch();
batch.AddExportedValue("untyped", 19);
batch.RemovePart(rb);
batch.AddPart(us);
container.Compose(batch);
Assert.IsNotNull(us.Exports, "Should have an enumeration");
Assert.AreEqual(2, us.Exports.Count(), "Should have 2 values");
}
示例6: ExportsChanged_ExportRemoved_ShouldFireExportsChanged
public void ExportsChanged_ExportRemoved_ShouldFireExportsChanged()
{
var container = CreateCompositionContainer();
IEnumerable<string> changedNames = null;
CompositionBatch batch = new CompositionBatch();
var part = batch.AddExportedValue("MyExport", new object());
container.Compose(batch);
container.ExportsChanged += (sender, args) =>
{
Assert.AreSame(container, sender);
Assert.IsNull(changedNames, "Ensure this event only fires once!");
Assert.IsNotNull(args.AddedExports);
Assert.IsNotNull(args.RemovedExports);
Assert.IsNotNull(args.ChangedContractNames);
changedNames = args.ChangedContractNames;
};
batch = new CompositionBatch();
batch.RemovePart(part);
container.Compose(batch);
EnumerableAssert.AreEqual(changedNames, "MyExport");
}
示例7: ComposeDisposableChildContainer
public void ComposeDisposableChildContainer()
{
var outerContainer = CreateCompositionContainer();
Int32Importer outerImporter = new Int32Importer();
CompositionBatch outerBatch = new CompositionBatch();
var key = outerBatch.AddExportedValue("Value", 42);
outerBatch.AddPart(outerImporter);
outerContainer.Compose(outerBatch);
Assert.AreEqual(42, outerImporter.Value, "Expected value imported from export");
Int32Importer innerImporter = new Int32Importer();
var innerContainer = new CompositionContainer(outerContainer);
CompositionBatch innerBatch = new CompositionBatch();
innerBatch.AddPart(innerImporter);
innerContainer.Compose(innerBatch);
Assert.AreEqual(42, innerImporter.Value, "Expected value imported from export");
Assert.AreEqual(42, outerImporter.Value, "Expected value imported from export");
outerBatch = new CompositionBatch();
outerBatch.RemovePart(key);
key = outerBatch.AddExportedValue("Value", -5);
outerContainer.Compose(outerBatch);
Assert.AreEqual(-5, innerImporter.Value, "Expected update value imported from export");
Assert.AreEqual(-5, outerImporter.Value, "Expected updated value imported from export");
innerContainer.Dispose();
outerBatch = new CompositionBatch();
outerBatch.RemovePart(key);
key = outerBatch.AddExportedValue("Value", 500);
outerContainer.Compose(outerBatch);
Assert.AreEqual(500, outerImporter.Value, "Expected updated value imported from export");
Assert.AreEqual(-5, innerImporter.Value, "Expected value not updated");
}
示例8: RemovePart_PartInContainerQueueAsPartArgument_ShouldNotLeavePartInContainer
public void RemovePart_PartInContainerQueueAsPartArgument_ShouldNotLeavePartInContainer()
{
const string contractName = "Contract";
var exporter = PartFactory.CreateExporter(new MicroExport(contractName, 1));
var importer = PartFactory.CreateImporter(contractName);
var container = ContainerFactory.Create(exporter, importer);
CompositionBatch batch = new CompositionBatch();
batch.RemovePart(exporter);
container.Compose(batch);
Assert.IsNull(importer.Value);
Assert.AreEqual(2, importer.ImportSatisfiedCount);
}
示例9: SharedPart_DisposableRecomposabeImport_ShouldNotBeCollected
public void SharedPart_DisposableRecomposabeImport_ShouldNotBeCollected()
{
var catalog = new TypeCatalog(typeof(SharedPartDisposableRecomposable));
var container = new CompositionContainer(catalog);
// Setup dependency
CompositionBatch batch = new CompositionBatch();
var valueKey = batch.AddExportedValue("Value", 21);
container.Compose(batch);
batch = null;
var refTracker = new ReferenceTracker();
refTracker.AddReferencesNotExpectedToBeCollected(
container.GetExportedValue<SharedPartDisposableRecomposable>());
refTracker.CollectAndAssert();
// Lets make sure recomposition doesn't blow anything up here.
batch = new CompositionBatch();
batch.RemovePart(valueKey);
batch.AddExportedValue("Value", 42);
container.Compose(batch);
batch = null;
var exportedValue = (SharedPartDisposableRecomposable)refTracker.ReferencesNotExpectedToBeCollected[0].Target;
Assert.AreEqual(42, exportedValue.Value);
container.Dispose();
Assert.IsTrue(exportedValue.IsDisposed, "Any parts should be disposed with the container!");
}
示例10: AnyPart_RecomposabeImport_ShouldNotBeCollected
public void AnyPart_RecomposabeImport_ShouldNotBeCollected()
{
var catalog = new TypeCatalog(typeof(AnyPartRecomposable));
var container = new CompositionContainer(catalog);
// Setup dependency
CompositionBatch batch = new CompositionBatch();
var valueKey = batch.AddExportedValue("Value", 21);
container.Compose(batch);
batch = null;
var refTracker = new ReferenceTracker();
refTracker.AddReferencesNotExpectedToBeCollected(
container.GetExportedValue<AnyPartRecomposable>());
refTracker.CollectAndAssert();
// Lets make sure recomposition doesn't blow anything up here.
batch = new CompositionBatch();
batch.RemovePart(valueKey);
batch.AddExportedValue("Value", 42);
container.Compose(batch);
batch = null;
var exportedValue = (AnyPartRecomposable)refTracker.ReferencesNotExpectedToBeCollected[0].Target;
Assert.AreEqual(42, exportedValue.Value);
GC.KeepAlive(container);
}
示例11: NonSharedPart_RecomposableImport_NoReference_ShouldBeCollected
public void NonSharedPart_RecomposableImport_NoReference_ShouldBeCollected()
{
var catalog = new TypeCatalog(typeof(NonSharedPartRecomposable));
var container = new CompositionContainer(catalog);
// Setup dependency
CompositionBatch batch = new CompositionBatch();
var valueKey = batch.AddExportedValue("Value", 21);
container.Compose(batch);
batch = null;
var refTracker = new ReferenceTracker();
refTracker.AddReferencesExpectedToBeCollected(
container.GetExportedValue<NonSharedPartRecomposable>());
refTracker.CollectAndAssert();
// Recompose just to ensure we don't blow up, even though we don't expect anything to happen.
batch = new CompositionBatch();
batch.RemovePart(valueKey);
batch.AddExportedValue("Value", 42);
container.Compose(batch);
batch = null;
GC.KeepAlive(container);
}
示例12: UnLoadPlugin
/// <summary>
/// 卸载插件
/// </summary>
/// <param name="plugin"></param>
/// <returns></returns>
private bool UnLoadPlugin(IPlugin plugin)
{
bool isSuccess = false;
try
{
var batch = new CompositionBatch();
var part = AttributedModelServices.CreatePart(plugin);
//var part = batch.AddExportedValue<IPlugin>(plugin);
//var part2 = _container.GetExportedValues<IPlugin>().First();
//Lazy<IPlugin> part3 = _container.GetExport<IPlugin>();
//IPlugin tmp = part3.Value;
batch.RemovePart(part);
_container.Compose(batch);
//_container.ReleaseExport(part3);
isSuccess = true;
}
catch
{
isSuccess = false;
}
return isSuccess;
}
示例13: OptionalImportsOfExportReferenceTypesAreReboundToDefaultWhenExportIsRemoved
public void OptionalImportsOfExportReferenceTypesAreReboundToDefaultWhenExportIsRemoved()
{
var container = ContainerFactory.Create();
var importer = new OptionalExport();
CompositionBatch batch = new CompositionBatch();
batch.AddPart(importer);
var key = batch.AddExportedValue("ReferenceType", "Bar");
container.Compose(batch);
Assert.AreEqual(1, importer.ReferenceTypeSetCount);
Assert.AreEqual("Bar", importer.ReferenceType.Value);
batch = new CompositionBatch();
batch.RemovePart(key);
container.Compose(batch);
Assert.AreEqual(2, importer.ReferenceTypeSetCount);
Assert.IsNull(importer.ReferenceType);
}
示例14: OptionalImportsOfNullableValueTypesAreReboundToDefaultWhenExportIsRemoved
public void OptionalImportsOfNullableValueTypesAreReboundToDefaultWhenExportIsRemoved()
{
var container = ContainerFactory.Create();
var importer = new OptionalImport();
CompositionBatch batch = new CompositionBatch();
batch.AddPart(importer);
var key = batch.AddExportedValue<int?>("NullableValueType", 10);
container.Compose(batch);
Assert.AreEqual(1, importer.NullableValueTypeSetCount);
Assert.AreEqual(10, importer.NullableValueType);
batch = new CompositionBatch();
batch.RemovePart(key);
container.Compose(batch);
Assert.AreEqual(2, importer.NullableValueTypeSetCount);
Assert.IsNull(importer.NullableValueType);
}
示例15: Rejection_DefendPromisesOnceMade
public void Rejection_DefendPromisesOnceMade()
{
var container = ContainerFactory.CreateWithAttributedCatalog(typeof(Needy));
var addBatch = new CompositionBatch();
var removeBatch = new CompositionBatch();
var addedPart = addBatch.AddPart(new NoImportPart());
removeBatch.RemovePart(addedPart);
// Add then remove should be fine as long as exports aren't used yet.
container.Compose(addBatch);
container.Compose(removeBatch);
// Add the dependencies
container.Compose(addBatch);
// Retrieve needy which uses an export from addedPart
var export = container.GetExportedValue<Needy>();
// Should not be able to remove the addedPart because someone depends on it.
ExceptionAssert.Throws<ChangeRejectedException>(() =>
container.Compose(removeBatch));
}