Open GoogleCodeExporter opened 9 years ago
Are you running it on the client side? because it should work, can you provide
the generated js code when enumerating a jquery object?
Thanks
Dan-el
Original comment by DanelK...@gmail.com
on 5 Dec 2012 at 6:55
Issue 220 has been merged into this issue.
Original comment by yvan.rod...@gmail.com
on 13 Jan 2013 at 1:51
Workaround: add this to javascript code:
jQuery.fn.GetEnumerator = function () {
return new ArrayEnumerator.ctor(this);
}
Original comment by yvan.rod...@gmail.com
on 13 Jan 2013 at 1:55
Dan-el, here is an example:
private void ToArrayBug()
{
var sample = new jQuery("<ul><li>1</li><li>2</li><li>3</li><li>4</li>");
var sampleEnumerable = from s in sample.children() select s;
var sampleArray1 = sampleEnumerable.ToArray();
var sampleList = new List<HtmlElement>();
foreach(var s in sample.children())
sampleList.Add(s);
var sampleArray2 = sampleList.ToArray();
}
compiles to:
ToArrayBug: function ()
{
var sample = $("<ul><li>1</li><li>2</li><li>3</li><li>4</li>");
var sampleEnumerable = System.Linq.Enumerable.Select$2$$IEnumerable$1$$Func$2(HTMLElement, HTMLElement, sample.children(), $CreateAnonymousDelegate(this, function (s)
{
return s;
}));
var sampleArray1 = System.Linq.Enumerable.ToArray$1(HTMLElement, sampleEnumerable);
var sampleList = new System.Collections.Generic.List$1.ctor(HTMLElement);
for (var $i20 = 0, $t20 = sample.children(), $l20 = $t20.length, s = $t20[$i20]; $i20 < $l20; $i20++, s = $t20[$i20])
sampleList.Add(s);
var sampleArray2 = sampleList.ToArray();
}
which throws "Uncaught TypeError: Object [object Object] has no method
'GetEnumerator'" in
System.Linq.Enumerable.WhereSelectEnumerableIterator.MoveNext(). It's correct.
Original comment by yvan.rod...@gmail.com
on 13 Jan 2013 at 2:00
Yes, jQuery implements IEnumerable in order to enable foreach, although it also
implements IJsEnumerable, in order to identify the class as native enumerable,
which means that it's possible to iterate it like an array. You're correct that
this might be confusing, although unless you're using clr mode, you're not
supposed to use LINQ. If you are, then it's possible to inject your suggested
code in order to properly support it.
Original comment by DanelK...@gmail.com
on 14 Jan 2013 at 8:24
Original issue reported on code.google.com by
yvan.rod...@gmail.com
on 5 Dec 2012 at 6:19