or shoehorning in what the C# library should have included in the first place.
public static void Each<T>(this IEnumerable<T> source, Action<T> a){
foreach (var item in source)
a(item);
}
public static void Each(this IEnumerable source, Action<object> a){
foreach (var item in source)
a(item);
}
See my previous extension method, Join.
I should be able to do something like:
var table = new HtmlTable {
Rows = { // <-- error is here
from XmlNode p in node.SelectNodes("./property")
select new HtmlTableRow{
Cells = {
new HtmlTableCell{ InnerText = Server.HtmlEncode(p.Attributes["description"].Value) },
new HtmlTableCell{ InnerText = Server.HtmlEncode(p.InnerText) }
}
}
}
};
But I can't, because the LINQ code isn't "expanded" so the compiler complains that while it expects an HtmlTableRow element between the braces assigned to Rows, you're giving it a collection. But, you can't assign the collection to Rows directly because it's a read-only property.
Bad class design (Rows being read-only... same as Cells fwiw) or bad language design in that there's no way to "expand" the results of the LINQ query to do what seems natural in that spot?
Instead, I have to do:
var rows =
from XmlNode p in node.SelectNodes("./property")
select new HtmlTableRow{
Cells = {
new HtmlTableCell{ InnerText = Server.HtmlEncode(p.Attributes["description"].Value) },
new HtmlTableCell{ InnerText = Server.HtmlEncode(p.InnerText) }
}
};
var table = new HtmlTable();
foreach (var r in rows)
table.Rows.Add(r);
which is redundant.
Perl 6 1.0 in March?
Doh, my mistake. I'm aware of therelation between Parrot and Rakudobut I'...
Keith: Dec 2, 1:03am