/// <summary> Evaluates 'new List<T>(iEnumerableValue)' in the debuggee. </summary> public static Value CreateListFromIEnumerable(ParameterizedType ienumerableType, Value iEnumerableValue) { var ilistDef = ienumerableType.Compilation.FindType(typeof(List <>)).GetDefinition(); var ilistType = new ParameterizedType(ilistDef, ienumerableType.TypeArguments); var ctors = ilistType.GetConstructors(m => m.Parameters.Count == 1); var ctor = ctors.Single(m => m.Parameters[0].Type.IsKnownType(KnownTypeCode.IEnumerableOfT)); return(Eval.NewObject(WindowsDebugger.EvalThread, ctor, new Value[] { iEnumerableValue })); }
public static IL.ILInstruction CreateTuple(ICompilation compilation, params IL.ILInstruction[] nodes) { var restTuple = typeof(ValueTuple <, , , , , , ,>); Debug.Assert(restTuple.GetGenericArguments().Last().Name == "TRest"); var maxSize = restTuple.GetGenericArguments().Length; if (nodes.Length >= maxSize) { return(makeTuple(nodes.Take(maxSize - 1).Append(CreateTuple(compilation, nodes.Skip(maxSize - 1).ToArray())).ToArray())); } else { return(makeTuple(nodes)); } IL.ILInstruction makeTuple(IL.ILInstruction[] n) { var t = //n.Length == 0 ? typeof(ValueTuple) : n.Length == 1 ? typeof(ValueTuple <>) : n.Length == 2 ? typeof(ValueTuple <,>) : n.Length == 3 ? typeof(ValueTuple <, ,>) : n.Length == 4 ? typeof(ValueTuple <, , ,>) : n.Length == 5 ? typeof(ValueTuple <, , , ,>) : n.Length == 6 ? typeof(ValueTuple <, , , , ,>) : n.Length == 7 ? typeof(ValueTuple <, , , , , ,>) : n.Length == 8 ? typeof(ValueTuple <, , , , , , ,>) : throw new NotSupportedException($"ValueTuple can not have {n.Length} parameters"); var tt = new ParameterizedType(compilation.FindType(t), n.Select(a => a.GetObjectResultType())); var ctor = tt.GetConstructors().Single(c => c.Parameters.Count == n.Length); var result = new IL.NewObj(ctor); result.Arguments.AddRange(n); return(result); } }