clambertus opened a new issue #279:
URL: https://github.com/apache/lucenenet/issues/279


   <p>The Iterator pattern in Java is equivalent to IEnumerable in .NET.  
Classes that were directly ported in Java using the Iterator pattern, cannot be 
used with Linq or foreach blocks in .NET.</p>
   
   <p><tt>Next()</tt> would be equivalent to .NET's <tt>MoveNext()</tt>, and in 
the below case, <tt>Term()</tt> would be as .NET's <tt>Current</tt> property.  
In cases as below, it will require <tt>TermEnum</tt> to become an abstract 
class with <tt>Term</tt> and <tt>DocFreq</tt> properties, which would be 
returned from another class or method that implemented 
<tt>IEnumerable<TermEnum></tt>.</p>
   
   <div class="preformatted panel" style="border-width: 1px;"><div 
class="preformattedContent panelContent">
   <pre> 
        public abstract class TermEnum : IDisposable
        {
                public abstract bool Next();
                public abstract Term Term();
                public abstract int DocFreq();
                public abstract void  Close();
        public abstract void Dispose();
        }
   </pre>
   </div></div> 
   
   <p>would instead look something like:</p>
   
   <div class="preformatted panel" style="border-width: 1px;"><div 
class="preformattedContent panelContent">
   <pre> 
        public class TermFreq
        {
                public abstract Term { get; }
                public abstract int { get; }
        }
   
   public abstract class TermEnum : IEnumerable<TermFreq>, IDisposable
   {
   // ...
   }
   </pre>
   </div></div>
   
   <p>Keep in mind that it is important that if the class being converted 
implements <tt>IDisposable</tt>, the class that is enumerating the terms (in 
this case <tt>TermEnum</tt>) should inherit from both <tt>IEnumerable<T></tt> 
<b>and</b> <tt>IDisposable</tt>.  This won't be any change to the user, as the 
compiler automatically calls <tt>IDisposable</tt> when used in a 
<tt>foreach</tt> loop.</p>
   <i>JIRA link - <a 
href="https://issues.apache.org/jira/browse/LUCENENET-469";>[LUCENENET-469]</a> 
created by ccurrens</i>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to