Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need a contract(interface) and a metadata contract (interface):</p> <pre><code>public interface ICarPart{ int SomeMethodFromInterface(); } public interface ICarPartMetadata{ string /*attention to this!!!*/ NameCarPart { get; } /* Only for read. */ } </code></pre> <p>Then you export your parts:</p> <pre><code>[Export(typeof (ICarPart))] [ExportMetadata("NameCarPart","SteeringWheel")] /* is string!! */ public class SteeringWheel : ICarPart { public int SomeMethodFromInterface(){ ... //your stuff } } [Export(typeof (ICarPart))] [ExportMetadata("NameCarPart","Engine")] /* is string!! */ public class Engine : ICarPart { public int SomeMethodFromInterface(){ //Each method have diferent behavior in each part. ... //your stuff } } [Export(typeof (ICarPart))] [ExportMetadata("NameCarPart","Brakes")] /* is string!! */ public class Brakes : ICarPart { public int SomeMethodFromInterface(){ //Each method have diferent behavior in each part. ... //your stuff } } </code></pre> <p>Then you can import with ImportMany and Lazy:</p> <pre><code> [ImportMany()] IEnumerable&lt;Lazy&lt;ICarPart, ICarPartMetadata&gt;&gt; carParts = null; public void Importing(){ ... ... foreach (Lazy&lt;ICarPart,ICarPartMetadata&gt; item in carParts){ switch (item.Metadata.ICarPartMetadata.ToString()){ case "SteeringWheel": item.Value.SomeMethodFromInterface(); break; case "Engine": item.Value.SomeMethodFromInterface(); break; case "Brakes": item.Value.SomeMethodFromInterface(); break; default: ... break; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload