public void DebuggerDisplayAttribute() { var source = @"using System.Diagnostics; [DebuggerDisplay(""F={F}"")] class A { internal object F; } class B { (A, A) F = (new A() { F = 1 }, new A() { F = 2 }); }"; var assembly0 = GenerateTupleAssembly(); var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference(); var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 }); var assembly1 = compilation1.EmitToArray(); var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1))); using (runtime.Load()) { var type = runtime.GetType("B"); var value = type.Instantiate(); var evalResult = FormatResult("o", value); var children = GetChildren(evalResult); Verify(children, EvalResult("F", "({A}, {A})", "(A, A)", "o.F", DkmEvaluationResultFlags.Expandable)); children = GetChildren(children[0]); Verify(children, EvalResult("Item1", "F=1", "A", "o.F.Item1", DkmEvaluationResultFlags.Expandable), EvalResult("Item2", "F=2", "A", "o.F.Item2", DkmEvaluationResultFlags.Expandable)); } }
public void Keywords() { var source = @"namespace @namespace { struct @struct { } } class async { (async @var, @namespace.@struct @class) F; }"; var assembly0 = GenerateTupleAssembly(); var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference(); var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 }); var assembly1 = compilation1.EmitToArray(); var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1))); using (runtime.Load()) { var type = runtime.GetType("async"); var value = type.Instantiate(); var evalResult = FormatResult("o", value); Verify(evalResult, EvalResult("o", "{async}", "async", "o", DkmEvaluationResultFlags.Expandable)); var children = GetChildren(evalResult); Verify(children, EvalResult("F", "(null, {namespace.struct})", "(async, namespace.struct)", "o.F", DkmEvaluationResultFlags.Expandable)); } }
public void LongTuple() { var source = @"class C { (short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short) _17 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); }"; var assembly0 = GenerateTupleAssembly(); var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference(); var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 }); var assembly1 = compilation1.EmitToArray(); var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1))); using (runtime.Load()) { var inspectionContext = CreateDkmInspectionContext(radix: 16); var type = runtime.GetType("C"); var value = type.Instantiate(); var evalResult = FormatResult("o", value, inspectionContext: inspectionContext); Verify(evalResult, EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable)); var children = GetChildren(evalResult, inspectionContext); Verify(children, EvalResult( "_17", "(0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)", "(short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short)", "o._17", DkmEvaluationResultFlags.Expandable)); children = GetChildren(children[0], inspectionContext); Assert.Equal(8, children.Length); // Should be 18. https://github.com/dotnet/roslyn/issues/13421 var child = children[children.Length - 1]; Verify(child, EvalResult( "Rest", "(0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)", "(short, short, short, short, short, short, short, short, short, short)", "o._17.Rest", DkmEvaluationResultFlags.Expandable)); children = GetChildren(child, inspectionContext); Assert.Equal(8, children.Length); // Should be 11. https://github.com/dotnet/roslyn/issues/13421 child = children[children.Length - 1]; Verify(child, EvalResult( "Rest", "(0x000f, 0x0010, 0x0011)", "(short, short, short)", "o._17.Rest.Rest", DkmEvaluationResultFlags.Expandable)); } }
public void Tuples() { var source = @"using System; class C { object _1 = new ValueTuple<int>(1); object _2 = new ValueTuple<int, int>(1, 2); object _3 = new ValueTuple<int, int, int>(1, 2, 3); object _4 = new ValueTuple<int, int, int, int>(1, 2, 3, 4); object _5 = new ValueTuple<int, int, int, int, int>(1, 2, 3, 4, 5); object _6 = new ValueTuple<int, int, int, int, int, int>(1, 2, 3, 4, 5, 6); object _7 = new ValueTuple<int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7); object _8 = new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int>(8)); object _8A = new ValueTuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8); object _9 = new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int, int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int, int>(8, 9)); }"; var assembly0 = GenerateTupleAssembly(); var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference(); var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 }); var assembly1 = compilation1.EmitToArray(); var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1))); using (runtime.Load()) { var type = runtime.GetType("C"); var value = type.Instantiate(); var evalResult = FormatResult("o", value); Verify(evalResult, EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable)); var children = GetChildren(evalResult); Verify(children, EvalResult("_1", "{System.ValueTuple<int>}", "object {System.ValueTuple<int>}", "o._1", DkmEvaluationResultFlags.Expandable), EvalResult("_2", "(1, 2)", "object {(int, int)}", "o._2", DkmEvaluationResultFlags.Expandable), EvalResult("_3", "(1, 2, 3)", "object {(int, int, int)}", "o._3", DkmEvaluationResultFlags.Expandable), EvalResult("_4", "(1, 2, 3, 4)", "object {(int, int, int, int)}", "o._4", DkmEvaluationResultFlags.Expandable), EvalResult("_5", "(1, 2, 3, 4, 5)", "object {(int, int, int, int, int)}", "o._5", DkmEvaluationResultFlags.Expandable), EvalResult("_6", "(1, 2, 3, 4, 5, 6)", "object {(int, int, int, int, int, int)}", "o._6", DkmEvaluationResultFlags.Expandable), EvalResult("_7", "(1, 2, 3, 4, 5, 6, 7)", "object {(int, int, int, int, int, int, int)}", "o._7", DkmEvaluationResultFlags.Expandable), EvalResult("_8", "(1, 2, 3, 4, 5, 6, 7, 8)", "object {(int, int, int, int, int, int, int, int)}", "o._8", DkmEvaluationResultFlags.Expandable), EvalResult("_8A", "{System.ValueTuple<int, int, int, int, int, int, int, int>}", "object {System.ValueTuple<int, int, int, int, int, int, int, int>}", "o._8A", DkmEvaluationResultFlags.Expandable), EvalResult("_9", "(1, 2, 3, 4, 5, 6, 7, 8, 9)", "object {(int, int, int, int, int, int, int, int, int)}", "o._9", DkmEvaluationResultFlags.Expandable)); } }
private static ImmutableArray <byte> GenerateTupleAssembly() { var source = @"namespace System { public struct ValueTuple<T1> { public T1 Item1; public ValueTuple(T1 _1) { Item1 = _1; } } public struct ValueTuple<T1, T2> { public T1 Item1; public T2 Item2; public ValueTuple(T1 _1, T2 _2) { Item1 = _1; Item2 = _2; } } public struct ValueTuple<T1, T2, T3> { public T1 Item1; public T2 Item2; public T3 Item3; public ValueTuple(T1 _1, T2 _2, T3 _3) { Item1 = _1; Item2 = _2; Item3 = _3; } } public struct ValueTuple<T1, T2, T3, T4> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public ValueTuple(T1 _1, T2 _2, T3 _3, T4 _4) { Item1 = _1; Item2 = _2; Item3 = _3; Item4 = _4; } } public struct ValueTuple<T1, T2, T3, T4, T5> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public T5 Item5; public ValueTuple(T1 _1, T2 _2, T3 _3, T4 _4, T5 _5) { Item1 = _1; Item2 = _2; Item3 = _3; Item4 = _4; Item5 = _5; } } public struct ValueTuple<T1, T2, T3, T4, T5, T6> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public T5 Item5; public T6 Item6; public ValueTuple(T1 _1, T2 _2, T3 _3, T4 _4, T5 _5, T6 _6) { Item1 = _1; Item2 = _2; Item3 = _3; Item4 = _4; Item5 = _5; Item6 = _6; } } public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public T5 Item5; public T6 Item6; public T7 Item7; public ValueTuple(T1 _1, T2 _2, T3 _3, T4 _4, T5 _5, T6 _6, T7 _7) { Item1 = _1; Item2 = _2; Item3 = _3; Item4 = _4; Item5 = _5; Item6 = _6; Item7 = _7; } } public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public T5 Item5; public T6 Item6; public T7 Item7; public T8 Rest; public ValueTuple(T1 _1, T2 _2, T3 _3, T4 _4, T5 _5, T6 _6, T7 _7, T8 _8) { Item1 = _1; Item2 = _2; Item3 = _3; Item4 = _4; Item5 = _5; Item6 = _6; Item7 = _7; Rest = _8; } } } namespace System.Runtime.CompilerServices { public class TupleElementNamesAttribute : Attribute { public TupleElementNamesAttribute(string[] names) { } } }"; var comp = CSharpTestBaseBase.CreateCompilationWithMscorlib(source); comp.VerifyDiagnostics(); return(comp.EmitToArray()); }