using System; using System.Threading.Tasks; namespace DebuggerTests { public class ValueTypesTest { //Only append content to this class as the test suite depends on line info public static void MethodWithLocalStructs () { var ss_local = new SimpleStruct ("set in MethodWithLocalStructs", 1, DateTimeKind.Utc); var gs_local = new GenericStruct { StringField = "gs_local#GenericStruct#StringField" }; ValueTypesTest vt_local = new ValueTypesTest { StringField = "string#0", SimpleStructField = new SimpleStruct ("SimpleStructField#string#0", 5, DateTimeKind.Local), SimpleStructProperty = new SimpleStruct ("SimpleStructProperty#string#0", 2, DateTimeKind.Utc), DT = new DateTime (2020, 1, 2, 3, 4, 5), RGB = RGB.Blue }; Console.WriteLine ($"Using the struct: {ss_local.gs.StringField}, gs: {gs_local.StringField}, {vt_local.StringField}"); } public static void TestStructsAsMethodArgs () { var ss_local = new SimpleStruct ("ss_local#SimpleStruct#string#0", 5, DateTimeKind.Local); var ss_ret = MethodWithStructArgs ("TestStructsAsMethodArgs#label", ss_local, 3); Console.WriteLine ($"got back ss_local: {ss_local.gs.StringField}, ss_ret: {ss_ret.gs.StringField}"); } static SimpleStruct MethodWithStructArgs (string label, SimpleStruct ss_arg, int x) { Console.WriteLine ($"- ss_arg: {ss_arg.str_member}"); ss_arg.Kind = DateTimeKind.Utc; ss_arg.str_member = $"ValueTypesTest#MethodWithStructArgs#updated#ss_arg#str_member"; ss_arg.gs.StringField = $"ValueTypesTest#MethodWithStructArgs#updated#gs#StringField#{x}"; return ss_arg; } public static async Task MethodWithLocalStructsStaticAsync () { var ss_local = new SimpleStruct ("set in MethodWithLocalStructsStaticAsync", 1, DateTimeKind.Utc); var gs_local = new GenericStruct { StringField = "gs_local#GenericStruct#StringField", List = new System.Collections.Generic.List { 5, 3 }, Options = Options.Option2 }; var result = await ss_local.AsyncMethodWithStructArgs (gs_local); Console.WriteLine ($"Using the struct: {ss_local.gs.StringField}, result: {result}"); return result; } public string StringField; public SimpleStruct SimpleStructProperty { get; set; } public SimpleStruct SimpleStructField; public struct SimpleStruct { public string str_member; public DateTime dt; public GenericStruct gs; public DateTimeKind Kind; public SimpleStruct (string str, int f, DateTimeKind kind) { str_member = $"{str}#SimpleStruct#str_member"; dt = new DateTime (2020+f, 1+f, 2+f, 3+f, 5+f, 6+f); gs = new GenericStruct { StringField = $"{str}#SimpleStruct#gs#StringField", List = new System.Collections.Generic.List { new DateTime (2010+f, 2+f, 3+f, 10+f, 2+f, 3+f) }, Options = Options.Option1 }; Kind = kind; } public Task AsyncMethodWithStructArgs (GenericStruct gs) { Console.WriteLine ($"placeholder line for a breakpoint"); if (gs.List.Count > 0) return Task.FromResult (true); return Task.FromResult (false); } } public struct GenericStruct { public System.Collections.Generic.List List; public string StringField; public Options Options { get; set; } } public DateTime DT { get; set; } public RGB RGB; public static void MethodWithLocalsForToStringTest (bool call_other) { var dt0 = new DateTime (2020, 1, 2, 3, 4, 5); var dt1 = new DateTime (2010, 5, 4, 3, 2, 1); var ts = dt0 - dt1; var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0)); decimal dec = 123987123; var guid = new Guid ("3d36e07e-ac90-48c6-b7ec-a481e289d014"); var dts = new DateTime [] { new DateTime (1983, 6, 7, 5, 6, 10), new DateTime (1999, 10, 15, 1, 2, 3) }; var obj = new ClassForToStringTests { DT = new DateTime (2004, 10, 15, 1, 2, 3), DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0)), TS = ts, Dec = 1239871, Guid = guid }; var sst = new StructForToStringTests { DT = new DateTime (2004, 10, 15, 1, 2, 3), DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0)), TS = ts, Dec = 1239871, Guid = guid }; Console.WriteLine ($"MethodWithLocalsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}"); if (call_other) MethodWithArgumentsForToStringTest (call_other, dt0, dt1, ts, dto, dec, guid, dts, obj, sst); } static void MethodWithArgumentsForToStringTest ( bool call_other, // not really used, just to help with using common code in the tests DateTime dt0, DateTime dt1, TimeSpan ts, DateTimeOffset dto, decimal dec, Guid guid, DateTime[] dts, ClassForToStringTests obj, StructForToStringTests sst) { Console.WriteLine ($"MethodWithArgumentsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}"); } public static async Task MethodWithLocalsForToStringTestAsync (bool call_other) { var dt0 = new DateTime (2020, 1, 2, 3, 4, 5); var dt1 = new DateTime (2010, 5, 4, 3, 2, 1); var ts = dt0 - dt1; var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0)); decimal dec = 123987123; var guid = new Guid ("3d36e07e-ac90-48c6-b7ec-a481e289d014"); var dts = new DateTime [] { new DateTime (1983, 6, 7, 5, 6, 10), new DateTime (1999, 10, 15, 1, 2, 3) }; var obj = new ClassForToStringTests { DT = new DateTime (2004, 10, 15, 1, 2, 3), DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0)), TS = ts, Dec = 1239871, Guid = guid }; var sst = new StructForToStringTests { DT = new DateTime (2004, 10, 15, 1, 2, 3), DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0)), TS = ts, Dec = 1239871, Guid = guid }; Console.WriteLine ($"MethodWithLocalsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}"); if (call_other) await MethodWithArgumentsForToStringTestAsync (call_other, dt0, dt1, ts, dto, dec, guid, dts, obj, sst); } static async Task MethodWithArgumentsForToStringTestAsync ( bool call_other, // not really used, just to help with using common code in the tests DateTime dt0, DateTime dt1, TimeSpan ts, DateTimeOffset dto, decimal dec, Guid guid, DateTime[] dts, ClassForToStringTests obj, StructForToStringTests sst) { Console.WriteLine ($"MethodWithArgumentsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}"); } } class ClassForToStringTests { public DateTime DT; public DateTimeOffset DTO; public TimeSpan TS; public decimal Dec; public Guid Guid; } struct StructForToStringTests { public DateTime DT; public DateTimeOffset DTO; public TimeSpan TS; public decimal Dec; public Guid Guid; } public enum RGB { Red, Green, Blue } [Flags] public enum Options { None = 0, Option1 = 1, Option2 = 2, Option3 = 4, All = Option1 | Option3 } }