Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Encapsulate <code>Dictionary&lt;string, string&gt;</code> as a composed field inside custom <code>class MyDictionary</code> and implement a custom <a href="http://msdn.microsoft.com/en-us/library/9eekhta0(VS.80).aspx" rel="nofollow noreferrer">IEnumerable</a> and <a href="http://msdn.microsoft.com/en-us/library/78dfe2yb(VS.80).aspx" rel="nofollow noreferrer">IEnumerator</a> (or variations thereof) for MyDictionary (or make a method that implements handy C# <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0(VS.80).aspx" rel="nofollow noreferrer"><code>yield</code></a> keyword to produce the items)...</p> <p>E.g.</p> <pre><code>class MyDictionary : IEnumerable&lt;KeyValuePair&lt;string,string&gt;&gt; { Dictionary&lt;string, string&gt; _dict; IEnumerator&lt;KeyValuePair&lt;string,string&gt;&gt; GetEnumerator() { return new MyEnum(this); // use your enumerator // OR simply forget your own implementation and return _dict.GetEnumerator(); } class MyEnum : IEnumerator&lt;KeyValuePair&lt;string,string&gt;&gt; { internal MyEnum(MyDictionary dict) { //... dict } // implemented methods (.MoveNext, .Reset, .Current)... </code></pre> <p><strong>This maintains encapsulation of extraneous methods.</strong> And you can still iterate over you instances like so <strong>from inside or outside</strong>: </p> <pre><code>// from outside MyDictionary mdict = new MyDictionary(); foreach (KeyValuePair&lt;string, string&gt; kvp in mdict) //... // from inside, assuming: this == MyDictionary instance) public void MyDictionaryMethod() { foreach (KeyValuePair&lt;string, string&gt; kvp in this) //... </code></pre>
    singulars
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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