From 7cba5e418ba2b83eea4b0901407a484b03d8482d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Guldmund?= Date: Fri, 12 Jan 2024 16:56:34 +0100 Subject: [PATCH] #2 Add preprocessor directives to Sandbox This enables us to verify support for different target frameworks by running the sandbox. --- src/Sandbox/Program.cs | 91 +++++++++++++++++++++++++++++--------- src/Sandbox/Sandbox.csproj | 2 +- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/Sandbox/Program.cs b/src/Sandbox/Program.cs index 6697db4..78bf603 100644 --- a/src/Sandbox/Program.cs +++ b/src/Sandbox/Program.cs @@ -8,30 +8,81 @@ public class Program { public static void Main(string[] args) { - var dateTimeShim = Shim.Replace(() => T.I).With(() => "L"); - var dateTimeShim1 = Shim.Replace(() => T.Get()).With(() => "Word"); - var inst = new Inst(); - var f = new Func(i => "Word"); - var dateTimeShim2 = Shim.Replace(() => inst.S).With(f); - var dateTimeShim3 = Shim.Replace(() => inst.Get()).With(f); - var dateTimeShim4 = Shim.Replace(() => Is.A().S).With(f); - var dateTimeShim5 = Shim.Replace(() => Is.A().Get()).With(f); - var dateTimeShim6 = Shim.Replace(() => Is.A().Get()).With(delegate(Inst @this) { return "Word"; }); - +#if NET48 + Console.WriteLine("4.8"); + var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1)); PoseContext.Isolate( () => { - // Console.Write(T.I); - // Console.WriteLine(T.Get()); - try - { - Console.WriteLine(inst.S); - } - catch (Exception e) { } - finally { } + Console.WriteLine(DateTime.Now); + }, dateTimeShim); +#elif NETCOREAPP2_0 + Console.WriteLine("2.0"); + var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1)); + PoseContext.Isolate( + () => + { + Console.WriteLine(DateTime.Now); + }, dateTimeShim); +#elif NET6_0 + Console.WriteLine("6.0"); + var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1)); + PoseContext.Isolate( + () => + { + Console.WriteLine(DateTime.Now); + }, dateTimeShim); +#elif NET7_0 + Console.WriteLine("7.0"); + + var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1)); + PoseContext.Isolate( + () => + { + Console.WriteLine(DateTime.Now); + }, dateTimeShim); +#elif NETCOREAPP3_0 + Console.WriteLine("3.0"); + var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1)); + PoseContext.Isolate( + () => + { + Console.WriteLine(DateTime.Now); + }, dateTimeShim); +#else + Console.WriteLine("Other"); + var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1)); + PoseContext.Isolate( + () => + { + Console.WriteLine(DateTime.Now); + }, dateTimeShim); +#endif - // Console.WriteLine(T.I); - }, dateTimeShim, dateTimeShim4); + // var dateTimeShim = Shim.Replace(() => T.I).With(() => "L"); + // var dateTimeShim1 = Shim.Replace(() => T.Get()).With(() => "Word"); + // var inst = new Inst(); + // var f = new Func(i => "Word"); + // var dateTimeShim2 = Shim.Replace(() => inst.S).With(f); + // var dateTimeShim3 = Shim.Replace(() => inst.Get()).With(f); + // var dateTimeShim4 = Shim.Replace(() => Is.A().S).With(f); + // var dateTimeShim5 = Shim.Replace(() => Is.A().Get()).With(f); + // var dateTimeShim6 = Shim.Replace(() => Is.A().Get()).With(delegate(Inst @this) { return "Word"; }); + // + // PoseContext.Isolate( + // () => + // { + // // Console.Write(T.I); + // // Console.WriteLine(T.Get()); + // try + // { + // Console.WriteLine(inst.S); + // } + // catch (Exception e) { } + // finally { } + // + // // Console.WriteLine(T.I); + // }, dateTimeShim, dateTimeShim4); } } diff --git a/src/Sandbox/Sandbox.csproj b/src/Sandbox/Sandbox.csproj index 147b638..5c0ed3b 100644 --- a/src/Sandbox/Sandbox.csproj +++ b/src/Sandbox/Sandbox.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.0;netcoreapp3.0;net6.0;net7.0