ListInitExpression from Expression list fails with multiple expression types. #16317
Open
Description
opened on Feb 6, 2016
Consider:
private class MixedAddable : IEnumerable
{
private readonly List<string> _strings = new List<string>();
private readonly List<int> _ints = new List<int>();
public void Add(string value)
{
_strings.Add(value);
}
public void Add(int value)
{
_ints.Add(value);
}
public IEnumerator GetEnumerator()
{
return _strings.Concat(_ints.Select(i => i.ToString())).GetEnumerator();
}
}
The likes of () => new MixedAddable { 1, "a", 2, "b" }
works fine, but the following fails:
Expression.ListInit(
Expression.New(typeof(MixedAddable)),
Expression.Constant(0),
Expression.Constant("a")
)
It's assumed that the correct Add
method for the first expression is also correct for the rest, though this doesn't necessarily hold.
Activity