[stringtemplate-interest] Problem with IEnumerator collections(c#2.3b7 )

Kunle Odutola Kunle_Odutola at hotmail.com
Fri Jun 2 17:11:17 PDT 2006


Hi Kenny,

> I have an other alternative that should solve the problem
>
> // the following code would result in no change of the Enumerator
> try
> {
>     ((IEnumerator)a).current ;
>     // We must have a members in the list
>     return true ;
> }
> catch ( InvalidOperationException e )
> {
>     // can only be at start of list ;

// MatchNext() would only throw too until we Reset()
((IEnumerator)a).Reset() ;

>     Boolean res  = ((IEnumerator)a).MatchNext() ;
>     if ( res )
>     {
>         // put it back to start of list
>        ((IEnumerator)a).Rest() ;
>     }
> }

That's a nice variant of (a). There's a cost to setting up the exception
context but, I'll pop it into ST#. The enumerator testing isn't a
performance hotspot. I think you missed a Reset() call above though.

Thanks


Kunle


More information about the stringtemplate-interest mailing list