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

Kenny Cockburn kenny.cockburn at ntlworld.com
Fri Jun 2 16:53:54 PDT 2006


.......

a) Obvious fix: Reset() the enumerator after testing. This will still behave
incorrectly if the current position in the iterator is significant.
b) Ugly fix: Wrap *all* enumerator attributes to ensure consistent
behaviour.
c) Simplest fix: Restrict $if(enumerator)$ to testing object existense (i.e.
non-null) for enumerators.

I'm firmly in the (c) camp. What do you think?

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 ;
    Boolean res  = ((IEnumerator)a).MatchNext() ;
    if ( res ) 
    {
        // put it back to start of list 
       ((IEnumerator)a).Rest() ;
    }
}





More information about the stringtemplate-interest mailing list