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

Kunle Odutola Kunle_Odutola at hotmail.com
Fri Jun 2 10:47:19 PDT 2006


Hi Kenny,

> I create a simple class that only implements the IEnumerator interface ;
>
> I have a template that test if the collection has rows then prints the
> collections values
>
> In the case where we have an array everything works as expected  in the
> case of the IEnumerator the rest() method is not called in the $if$ test
> so the list starts on the second element also after the list has been
> consumed the Rest() method is not called so subsequent  use of the list
> results in an empty list

Thanks. This is indeed an issue with ST#. Specifically with my attempt to
support testing of non-empty enumerators in $if(..)$. You didn't need a
custom IEnumerator implementation. This will have triggered the issue as
well:

    System.Console.WriteLine("Run Test with simple Array's Enumerator");

    sta3 = stg.GetInstanceOf("Action");

    sta3.SetAttribute("Arg", myIntArray.GetEnumerator());

    System.Console.WriteLine(sta3.ToString());

Some options:
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?


Kunle



More information about the stringtemplate-interest mailing list