本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer.GetExport方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer.GetExport方法的具体用法?C# CompositionContainer.GetExport怎么用?C# CompositionContainer.GetExport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionContainer
的用法示例。
在下文中一共展示了CompositionContainer.GetExport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InteractiveWindowTestHost
internal InteractiveWindowTestHost()
{
_exportProvider = new CompositionContainer(
s_lazyCatalog.Value,
CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);
var contentTypeRegistryService = _exportProvider.GetExport<IContentTypeRegistryService>().Value;
Evaluator = new TestInteractiveEvaluator();
Window = _exportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(Evaluator);
Window.InitializeAsync().Wait();
}
示例2: InteractiveWindowTestHost
internal InteractiveWindowTestHost(Action<InteractiveWindow.State> stateChangedHandler = null)
{
ExportProvider = new CompositionContainer(
s_lazyCatalog.Value,
CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);
var contentTypeRegistryService = ExportProvider.GetExport<IContentTypeRegistryService>().Value;
Evaluator = new TestInteractiveEngine(contentTypeRegistryService);
Window = ExportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(Evaluator);
((InteractiveWindow)Window).StateChanged += stateChangedHandler;
Window.InitializeAsync().Wait();
}
示例3: MainWindow
public MainWindow() {
InitializeComponent();
EnvironmentsToolWindow.ViewCreated += EnvironmentsToolWindow_ViewCreated;
_container = new CompositionContainer(new AggregateCatalog(
new AssemblyCatalog(typeof(IInterpreterRegistryService).Assembly),
new AssemblyCatalog(typeof(IInterpreterOptionsService).Assembly)
));
EnvironmentsToolWindow.Interpreters = _container.GetExport<IInterpreterRegistryService>().Value;
EnvironmentsToolWindow.Service = _container.GetExport<IInterpreterOptionsService>().Value;
}
示例4: InteractiveWindowTestHost
internal InteractiveWindowTestHost(Action<InteractiveWindow.State> stateChangedHandler = null)
{
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());
_exportProvider = new CompositionContainer(
_lazyCatalog.Value,
CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);
var contentTypeRegistryService = _exportProvider.GetExport<IContentTypeRegistryService>().Value;
_window = _exportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(new TestInteractiveEngine(contentTypeRegistryService));
((InteractiveWindow)_window).StateChanged += stateChangedHandler;
_window.InitializeAsync().PumpingWait();
}
示例5: InteractiveWindowTestHost
public InteractiveWindowTestHost()
{
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());
var types = new[] { typeof(TestInteractiveEngine), typeof(InteractiveWindow) }.Concat(GetVisualStudioTypes());
_exportProvider = new CompositionContainer(
new AggregateCatalog(types.Select(t => new AssemblyCatalog(t.Assembly))),
CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);
var contentTypeRegistryService = _exportProvider.GetExport<IContentTypeRegistryService>().Value;
_window = _exportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(new TestInteractiveEngine(contentTypeRegistryService));
_window.InitializeAsync().PumpingWait();
}
示例6: Start
public void Start()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchDemo).Assembly));
var container = new CompositionContainer(catalog);
container.ComposeParts();
try
{
var component = container.GetExport<ITestComponent>();
if (component != null)
Console.WriteLine(component.Value.Message);
}
catch (Exception exp)
{
//Why does our call to 'GetExport' throw an exception?
//Search for the string "Test" on the container variable
//You'll find 3 instances in the Catalog.
//Then search for ITestComponent.
//You'll need to click "Search Deeper" to expand the search.
//Another way to do this is to view "container.Catalog.Parts", right click it,
//select 'Edit Filter' and enter the following predicate:
// [obj].Exports(typoef(ITestComponent)
MessageBox.Show(exp.Message, "Exception caught!");
}
}
示例7: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog("."));
var container = new CompositionContainer(catalog);
try
{
container.ComposeParts(this);
container.ComposeExportedValue("container", container);
Lazy<IModuleController> controller = container.GetExport<IModuleController>();
if (controller == null) return;
controller.Value.CompositionContainer = container;
controller.Value.Run();
}
catch (CompositionException exception)
{
MessageBox.Show(exception.ToString());
}
}
示例8: Main
static void Main()
{
var engine = new GUILayer.EngineDevice();
GC.KeepAlive(engine);
var catalog = new TypeCatalog(
typeof(ShaderPatcherLayer.Manager),
typeof(ShaderFragmentArchive.Archive),
typeof(NodeEditorCore.ShaderFragmentArchiveModel),
typeof(NodeEditorCore.ModelConversion),
typeof(NodeEditorCore.ShaderFragmentNodeCreator),
typeof(NodeEditorCore.DiagramDocument),
typeof(ExampleForm)
);
using (var container = new CompositionContainer(catalog))
{
container.ComposeExportedValue<ExportProvider>(container);
container.ComposeExportedValue<CompositionContainer>(container);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(container.GetExport<ExampleForm>().Value);
}
engine.Dispose();
}
示例9: LoadServer
public static ServerEntry LoadServer(string path)
{
try
{
// Create a server entry for the server.
var serverEntry = new ServerEntry();
// Set the data.
serverEntry.ServerName = Path.GetFileNameWithoutExtension(path);
serverEntry.ServerPath = path;
// Create an assembly catalog for the assembly and a container from it.
var catalog = new AssemblyCatalog(Path.GetFullPath(path));
var container = new CompositionContainer(catalog);
// Get the exported server.
var server = container.GetExport<ISharpShellServer>().Value;
serverEntry.ServerType = server.ServerType;
serverEntry.ClassId = server.GetType().GUID;
serverEntry.Server = server;
return serverEntry;
}
catch (Exception)
{
// It's almost certainly not a COM server.
MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning");
return null;
}
}
示例10: GetValuesByType
public void GetValuesByType()
{
var cat = CatalogFactory.CreateDefaultAttributed();
var container = new CompositionContainer(cat);
string itestName = AttributedModelServices.GetContractName(typeof(ITest));
var e1 = container.GetExportedValues<ITest>();
var e2 = container.GetExports<ITest, object>(itestName);
Assert.IsInstanceOfType(e1.First(), typeof(T1), "First should be T1");
Assert.IsInstanceOfType(e1.Skip(1).First(), typeof(T2), "Second should be T2");
Assert.IsInstanceOfType(e2.First().Value, typeof(T1), "First should be T1");
Assert.IsInstanceOfType(e2.Skip(1).First().Value, typeof(T2), "Second should be T2");
CompositionContainer childContainer = new CompositionContainer(container);
CompositionBatch batch = new CompositionBatch();
batch.AddPart(new T1());
container.Compose(batch);
var t1 = childContainer.GetExportedValue<ITest>();
var t2 = childContainer.GetExport<ITest, object>(itestName);
Assert.IsInstanceOfType(t1, typeof(T1), "First (resolved) should be T1");
Assert.IsInstanceOfType(t2.Value, typeof(T1), "First (resolved) should be T1");
}
示例11: CanMakeSweetShopWithVanillaJellybeans
public void CanMakeSweetShopWithVanillaJellybeans()
{
TypeCatalog catalog = new TypeCatalog(typeof(VanillaJellybeanDispenser), typeof(SweetVendingMachine), typeof(SweetShop));
CompositionContainer container = new CompositionContainer(catalog);
SweetShop sweetShop = container.GetExport<SweetShop>().Value;
Assert.AreEqual(Jellybean.Vanilla, sweetShop.DispenseJellyBean());
}
示例12: CanMakeAniseedRootObject
public void CanMakeAniseedRootObject()
{
TypeCatalog catalog = new TypeCatalog(typeof(AniseedSweetShop));
CompositionContainer container = new CompositionContainer(catalog);
SweetShop sweetShop = container.GetExport<SweetShop>().Value;
Assert.AreEqual(Jellybean.Aniseed, sweetShop.DispenseJellyBean());
}
示例13: ClassExportsITemplateEditorOptionsForConsumptionByEditorClasses
public void ClassExportsITemplateEditorOptionsForConsumptionByEditorClasses()
{
using (var catalog = new TypeCatalog(typeof(T4ToolboxOptions)))
using (var container = new CompositionContainer(catalog))
{
Lazy<ITemplateEditorOptions> export = container.GetExport<ITemplateEditorOptions>();
Assert.IsInstanceOfType(export.Value, typeof(T4ToolboxOptions));
}
}
示例14: SimpleExport_part_with_metadata_is_properly_exported
public void SimpleExport_part_with_metadata_is_properly_exported()
{
var registry = new ConfigurationPartRegistry("mef.configuration");
var catalog = new ConventionCatalog(registry);
var container = new CompositionContainer(catalog);
var simpleExport = container.GetExport<SimpleExportWithMetadata, ISimpleMetadata>("simple-export");
Assert.That(simpleExport, Is.Not.Null);
Assert.That(simpleExport.Metadata.IntValue, Is.EqualTo(1234));
Assert.That(simpleExport.Metadata.StrValue, Is.EqualTo("some string"));
}
示例15: TypeCatalog
public void ContainerCanGetExportForSauceBéarnaise()
{
var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Concrete.SauceBéarnaise));
var container = new CompositionContainer(catalog);
Lazy<SauceBéarnaise> export =
container.GetExport<SauceBéarnaise>();
SauceBéarnaise sauce = export.Value;
Assert.NotNull(sauce);
}