diff options
Diffstat (limited to 'mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/System/ComponentModel/Composition/CompositionContainerExtensions.cs')
-rw-r--r-- | mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/System/ComponentModel/Composition/CompositionContainerExtensions.cs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/System/ComponentModel/Composition/CompositionContainerExtensions.cs b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/System/ComponentModel/Composition/CompositionContainerExtensions.cs deleted file mode 100644 index 3a5af3d9e0e..00000000000 --- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/System/ComponentModel/Composition/CompositionContainerExtensions.cs +++ /dev/null @@ -1,86 +0,0 @@ -// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.Composition;
-using System.Linq;
-using System.ComponentModel.Composition.Hosting;
-using System.ComponentModel.Composition.Primitives;
-
-namespace System.ComponentModel.Composition
-{
- internal static class CompositionContainerExtensions
- {
- public static bool IsPresent<T>(this ExportProvider container)
- {
- try
- {
- container.GetExportedValue<T>();
- return true;
- }
- catch (ImportCardinalityMismatchException)
- {
- return false;
- }
- }
-
- public static bool IsPresent(this ExportProvider container, string contractName)
- {
- try
- {
- container.GetExportedValue<object>(contractName);
- return true;
- }
- catch (ImportCardinalityMismatchException)
- {
- return false;
- }
- }
-
- public static void AddAndComposeExportedValue<T>(this CompositionContainer container, T exportedValue)
- {
- var batch = new CompositionBatch();
- batch.AddExportedValue<T>(exportedValue);
- container.Compose(batch);
- }
-
- public static void AddAndComposeExportedValue<T>(this CompositionContainer container, string contractName, T exportedValue)
- {
- var batch = new CompositionBatch();
- batch.AddExportedValue<T>(contractName, exportedValue);
- container.Compose(batch);
- }
-
- public static void AddParts(this CompositionBatch batch, params object[] parts)
- {
- foreach (object instance in parts)
- {
- ComposablePart part = instance as ComposablePart;
- if (part != null)
- {
- batch.AddPart(part);
- }
- else
- {
- batch.AddPart((object)instance);
- }
- }
- }
-
- public static ComposablePart AddExportedValue(this CompositionBatch batch, string contractName, Type contractType, object exportedValue)
- {
- string typeIdentity = AttributedModelServices.GetTypeIdentity(contractType);
-
- IDictionary<string, object> metadata = null;
-
- if (typeIdentity != null)
- {
- metadata = new Dictionary<string, object>();
- metadata.Add(CompositionConstants.ExportTypeIdentityMetadataName, typeIdentity);
- }
-
- return batch.AddExport(new Export(contractName, metadata, () => exportedValue));
- }
- }
-}
|