This project has moved. For the latest updates, please go here.
ReoScript support to enumerate over an object which implementing the IEnumerable interface in .NET.

Iterator Syntax

To iterate over an object using the for ... in syntax.

The array in ReoScript can be enumerated over every elements. (unlike JavaScript)
    var arr = ['a', 'b', 10, 30];

    // iterate array
    for (element in arr) {

The result is:

Enumerate over an object to get all names of property.
    var obj = { a: 10, b: 20 };
    for (key in obj) {
      console.log(key + " : " + obj[key]);

The result is:
    a : 10
    b : 20

String can also be enumerated over every characters.

Enumerator Support and Extension

Any .NET type implements IEnumerable interface will be available to enumerate in script. ReoScript support to enumerate the following interface:
  • IEnumerable
  • IDictionary<string, object>

For example:
    public class StringObject : ObjectValue, IEnumerable
      public string String { get; set; }

      public override IEnumerator GetEnumerator()
        for (int i = 0; i < String.Length; i++)
          yield return String[i];

Now StringObject supported to iterate using syntax:
    var a = 'hello';
    for(c in a) {

The result is:

Dynamic Type & ExpandoObject

ExpandoObject class is available in .NET Dynamic Language Runtime, which provides an ability to add or remove members of object at .NET Run-time. ExpandoObject implements the `IDictionary<string, object>` interface so can also be supported to enumerate in ReoScript.

Last edited Jul 11, 2013 at 1:49 AM by unvell, version 2