Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It sounds like your collection implements <code>IEnumerable</code>, not <code>IEnumerable&lt;T&gt;</code>, hence you need:</p> <pre><code>_resources.Cast&lt;LanguageEditorResource&gt;().Where(r =&gt; r.IsDirty) </code></pre> <p>Note that <code>Enumerable.Where</code> is defined on <code>IEnumerable&lt;T&gt;</code>, not <code>IEnumerable</code> - if you have the non-generic type, you need to use <code>Cast&lt;T&gt;</code> (or <code>OfType&lt;T&gt;</code>) to get the right type. The difference being that <code>Cast&lt;T&gt;</code> will throw an exception if it finds something that isn't a <code>T</code>, where-as <code>OfType&lt;T&gt;</code> simply ignores anything that isn't a <code>T</code>. Since you've stated that your collection <em>only</em> contains <code>LanguageEditorResource</code>, it is reasonable to check that assumption using <code>Cast&lt;T&gt;</code>, rather than silently drop data.</p> <p>Check also that you have "using System.Linq" (and are referencing System.Core (.NET 3.5; else LINQBridge with .NET 2.0) to get the <code>Where</code> extension method(s).</p> <p>Actually, it would be worth having your collection implement <code>IEnumerable&lt;LanguageResource&gt;</code> - which you could do quite simply using either the <code>Cast&lt;T&gt;</code> method, or an iterator block (<code>yield return</code>).</p> <p>[edit] To build on Richard Poole's note - you could write your <em>own</em> generic container here, presumably with <code>T : LanguageResource</code> (and using that <code>T</code> in the <code>Dictionary&lt;string,T&gt;</code>, and implementing <code>IEnumerable&lt;T&gt;</code> or <code>ICollection&lt;T&gt;</code>). Just a thought.</p>
 

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