Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as your example is concerned, you can think of <code>IEnumerable&lt;T&gt;</code> as being pretty much synonymous with <code>List&lt;T&gt;</code>: it's a collection of objects; it could be just one, it could be none, it could be a hundred. There's more to <code>IEnumerable</code> than that, but for your purposes that's as much as you need to think about.</p> <p>In this code:</p> <pre><code>[ImportMany] public IEnumerable&lt;IEmailAddressesProvider&gt; AddressProviders { get; set; } </code></pre> <p>you're asking MEF to gather all the exported implementations of <code>IEmailAddressesProvider</code>. What you get back is a collection of objects: even if it finds just one, you still get a collection with only one element. In this later line:</p> <pre><code>ev.ViewModel.ProviderName = AddressProviders; </code></pre> <p>I'm guessing that the left hand side is expecting a <code>string</code>, but the right hand side is a collection of <code>IEmailAddressesProvider</code>. Apart from the fact that you probably actually want the <code>ProviderName</code> property of the <code>IEmailAddressesProvider</code> and not the whole object, you also need to say which object in the collection to use. There are two ways you might deal with this:</p> <ol> <li><p><strong>If you know that there will only be one implementation of <code>IEmailAddressesProvider</code></strong>, then change <code>ImportMany</code> to <code>Import</code> like so</p> <pre><code>[Import] public IEmailAddressesProvider AddressProviders { get; set; } </code></pre> <p>and change that other assignment to <code>ev.ViewModel.ProviderName = AddressProviders.ProviderName</code>. Note that this will break as soon as you export a second implementation of <code>IEmailAddressesProvider</code>, so only do this if you really know there can only be one.</p></li> <li><strong>If there may be several implementations of <code>IEmailAddressesProvider</code></strong>, then you need to find the specific one you want. You would query the <code>AddressProviders</code> collection with something like <code>FirstOrDefault</code> (as the other answers have said) to find the right object and then use the <code>ProviderName</code> property from that result. It's not possible to say much more about the query you need from the code you've provided.</li> </ol>
    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