This repository was archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathJSIL.GetEnumerator.js
More file actions
66 lines (52 loc) · 2.24 KB
/
Copy pathJSIL.GetEnumerator.js
File metadata and controls
66 lines (52 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$jsilcore.$tArrayEnumerator = null;
JSIL.MakeArrayEnumerator = function (array, elementType) {
var tArrayEnumerator;
if (!elementType) {
if ($jsilcore.$tArrayEnumerator === null)
$jsilcore.$tArrayEnumerator = JSIL.ArrayEnumerator.Of(System.Object);
tArrayEnumerator = $jsilcore.$tArrayEnumerator;
} else {
tArrayEnumerator = JSIL.ArrayEnumerator.Of(elementType);
}
return new tArrayEnumerator(array, -1);
};
JSIL.MakeStringEnumerator = function (array, elementType) {
var tArrayEnumerator;
if (!elementType) {
if ($jsilcore.$tArrayEnumerator === null)
$jsilcore.$tArrayEnumerator = JSIL.StringEnumerator.Of(System.Object);
tArrayEnumerator = $jsilcore.$tArrayEnumerator;
} else {
tArrayEnumerator = JSIL.StringEnumerator.Of(elementType);
}
return new tArrayEnumerator(array, -1);
};
JSIL.GetEnumerator = function (enumerable, elementType, fallbackMethodInvoke) {
if ((typeof (enumerable) === "undefined") || (enumerable === null))
JSIL.RuntimeError("Enumerable is null or undefined");
var tIEnumerable = $jsilcore.System.Collections.IEnumerable;
var tIEnumerable$b1 = null;
if (!elementType)
elementType = $jsilcore.System.Object.__Type__;
else
tIEnumerable$b1 = $jsilcore.System.Collections.Generic.IEnumerable$b1.Of(elementType);
var result = null;
if (JSIL.IsArray(enumerable))
result = JSIL.MakeArrayEnumerator(enumerable, elementType);
else if (enumerable.__IsArray__)
result = JSIL.MakeArrayEnumerator(enumerable.Items, elementType);
else if (typeof (enumerable) === "string")
result = JSIL.MakeStringEnumerator(enumerable, elementType);
else if ((fallbackMethodInvoke !== true) && tIEnumerable$b1 && tIEnumerable$b1.$Is(enumerable))
result = tIEnumerable$b1.GetEnumerator.Call(enumerable);
else if ((fallbackMethodInvoke !== true) && tIEnumerable.$Is(enumerable))
result = tIEnumerable.GetEnumerator.Call(enumerable);
else if ((fallbackMethodInvoke !== true) && (typeof (enumerable.GetEnumerator) === "function"))
// HACK: This is gross.
result = enumerable.GetEnumerator();
else
JSIL.RuntimeError("Value is not enumerable");
if (!result)
JSIL.RuntimeError("Value's GetEnumerator method did not return an enumerable.");
return result;
};