Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The return value of your <code>EnumerateAs()</code> should be <code>IEnumerable&lt;T&gt;</code>, where T is the type of object contained in your collection. I recommend reading more about <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx" rel="nofollow noreferrer">yield return</a>, as this may help you to understand how enumeration works. There is no default class for providing an enumeration 'strategy', but you can easily implement something like this by using yield return on the underlying collection in various ways.</p> <p>It's not clear from your question exactly how the enumeration strategies would interact with your collection class. It looks like you might be after something like:</p> <pre><code>public interface IEnumerationStrategy&lt;TCollection, T&gt; { IEnumerable&lt;T&gt; Enumerate(TCollection source); } public class Quark {} public class MyCollection { public IEnumerable&lt;Quark&gt; EnumerateAs(IEnumerationStrategy&lt;MyCollection, Quark&gt; strategy) { return strategy.Enumerate(this); } //Various special methods needed to implement stategies go here } public class SpecialStrategy : IEnumerationStrategy&lt;MyCollection, Quark&gt; { public IEnumerable&lt;Quark&gt; Enumerate(MyCollection source) { //Use special methods to do custom enumeration via yield return that depends on specifics of MyCollection } } </code></pre> <p>Note that you might also replace the strategy class with a simple strategy <code>Func&lt;MyCollection, IEnumerable&lt;T&gt;&gt;</code>, but the above matches your desired syntax most closely.</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