Language: C#
Overriding InheritedExport sample
/* Sample below illustatres export inheritance where the base export provides metadata that is overriden by the inheritor using an InheritedExport and ExportMetadata attributes. In this case OverridingExtension implements IExtension but then explicitly overrides the base and provides new metadata. The result is a single export rather than two exports. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; namespace InheritedExportTest { [TestClass] public class InheritedExportTests { [TestMethod] public void Overriding_extension_creates_a_single_export() { var catalog = new TypeCatalog(typeof (OverridingExtension)); var container = new CompositionContainer(catalog); var extensions = container.GetExportedValues<IExtension>(); Assert.AreEqual(1, extensions.Count()); //check that only one export exists } } [InheritedExport] //base export with no metadata public interface IExtension { } [ExportMetadata("Name", "OverridingExtension")] //metadata for the export [InheritedExport(typeof(IExtension))] //overrides the base export public class OverridingExtension : IExtension { } }
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

