[ 
https://issues.apache.org/jira/browse/LUCENENET-469?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16120064#comment-16120064
 ] 

Andy Pook commented on LUCENENET-469:
-------------------------------------

Yeah, well, I thought, that's looks like it might be isolated, small. Ha!
I'll poke at it some more, see what turns up. But I may just punt and look for 
something else :)

I'm not sure I'm on the same wave length just yet...

"how does that apply to TermsEnum? Disposing a superclass is not quite the same 
thing"
But the enumerator is not a super class. It's a "child" of the TermsEnum (or 
whatever) created for a purpose. Disposing the child shouldn't dispose the 
"parent". I'm fairly sure that IEnumerator has Dispose so that things like 
listing files (managed resource) can be cleaned up. But still, it's about 
cleaning up resources used by the enumerator _not_ by the parent collection 
type.
If you want to Dispose the collection type then that's a separate operation. 
There may be other behaviors available, appropriate on the collection type 
_after_ you've looped some aspect of it.
Right ??

Also a bit confused around the "extras" topic. I don't see the problem. We'd 
get all the linq bits for free. You're right, they are generally defined on 
{{IEnumerable<T>}} But that's fine. In your example of {{TermsEnum}} being 
{{IEnumerable<BytesRef>}} then regardless of how the enumerator is factored you 
can still do {{foreach(var item in termsEnum.Where(b=>b.Length>100)){}}}

> Convert Java Iterator classes to implement IEnumerable<T>
> ---------------------------------------------------------
>
>                 Key: LUCENENET-469
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-469
>             Project: Lucene.Net
>          Issue Type: Sub-task
>          Components: Lucene.Net Contrib, Lucene.Net Core
>    Affects Versions: Lucene.Net 2.9.4, Lucene.Net 2.9.4g, Lucene.Net 3.0.3, 
> Lucene.Net 4.8.0
>         Environment: all
>            Reporter: Christopher Currens
>             Fix For: Lucene.Net 4.8.0
>
>
> 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.
> {{Next()}} would be equivalent to .NET's {{MoveNext()}}, and in the below 
> case, {{Term()}} would be as .NET's {{Current}} property.  In cases as below, 
> it will require {{TermEnum}} to become an abstract class with {{Term}} and 
> {{DocFreq}} properties, which would be returned from another class or method 
> that implemented {{IEnumerable<TermEnum>}}.
> {noformat} 
>       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();
>       }
> {noformat} 
> would instead look something like:
> {noformat} 
>       public class TermFreq
>       {
>               public abstract Term { get; }
>               public abstract int { get; }
>       }
>         public abstract class TermEnum : IEnumerable<TermFreq>, IDisposable
>         {
>                 // ...
>         }
> {noformat}
> Keep in mind that it is important that if the class being converted 
> implements {{IDisposable}}, the class that is enumerating the terms (in this 
> case {{TermEnum}}) should inherit from both {{IEnumerable<T>}} *and* 
> {{IDisposable}}.  This won't be any change to the user, as the compiler 
> automatically calls {{IDisposable}} when used in a {{foreach}} loop.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to