c# - unexpected result in mef -


i beginner in mef. write code cant understand why program show result.

namespace consoleapplication1 {     public class meftest     {          [import]         public string text { get; set; }          [import]         public iextension ext { get; set; }          public void showtext()         {             assemblycatalog asscatalog = new assemblycatalog(typeof(extension2).assembly);             compositioncontainer container = new compositioncontainer(asscatalog);              compositionbatch batch = new compositionbatch();             batch.addpart(this);              container.compose(batch);              console.writeline(text);             console.writeline(ext.text);         }     }     class program     {         static void main( string[] args )         {             meftest mef = new meftest();              mef.showtext();              console.readkey();         }     }      public interface iextension     {         string text { get; set; }     }      [export]     public class extension1 : iextension     {         [export]         public string text { get; set; }          public extension1()         {             text = "from extension1.";         }     }      [export(typeof(iextension))]     public class extension2 : iextension     {        // [export(typeof(iextension).getproperties()[0].gettype())]         public string text { get; set; }          public extension2()         {             text = "from extension2.";         }     } }  

result :

from extension1. extension2.

this how mef matching imports. since have:

    [import]     public string text { get; set; } 

in case, mef finds "string text" , match. happens extention1, only because explicitly added export text property.

    [import]     public iextension ext { get; set; } 

this finds actual export of type iextension. 1 of these extension2 class. fulfills requirement.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -