Last active
August 29, 2015 14:25
-
-
Save mstrobel/7df0918b2072451d587c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
public static class C { | |
public static void M(object[] items) { | |
var cancelableItems = items.Cast<dynamic>() | |
.Where(d => d.CanCancel()) | |
.ToArray(); | |
// | |
// o.OrderId dynamically bound without problem with csc.exe in VS2013. | |
// | |
var tasks1 = cancelableItems.ToArray(o => F((long)o.OrderId)); | |
// | |
// Works fine if lambda parameter is explicitly typed. | |
// | |
var tasks2 = cancelableItems.ToArray((dynamic o) => F((long)o.OrderId)); | |
} | |
private static long F(long id) { | |
return id; | |
} | |
public static TResult[] ToArray<TResult>(this IEnumerable items, Func<object, TResult> selector) | |
{ | |
return ToArray(items.Cast<object>(), selector); | |
} | |
public static TResult[] ToArray<TSource, TResult>(this IEnumerable<TSource> items, Func<TSource, TResult> selector) | |
{ | |
return items.Select(selector).ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment