From 9eb4d5582fffae526e1aa6ea81a1a4be04a4a0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raymond=20Lei=28=E9=9B=B7=E8=8F=A9=E5=AE=87=29?= Date: Thu, 19 Dec 2024 20:59:49 -0500 Subject: [PATCH] Add ConditionalCompliationSampleClass.cs --- CSharp13/CSharp13.csproj | 15 +++ CSharp13/ConditionalCompliationSampleClass.cs | 118 ++++++++++++++++++ CSharpAndFSharpConsoleApp.sln | 14 +++ README.md | 8 +- 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 CSharp13/CSharp13.csproj create mode 100644 CSharp13/ConditionalCompliationSampleClass.cs diff --git a/CSharp13/CSharp13.csproj b/CSharp13/CSharp13.csproj new file mode 100644 index 0000000..ece3c3d --- /dev/null +++ b/CSharp13/CSharp13.csproj @@ -0,0 +1,15 @@ + + + + net9.0 + enable + enable + + + + + USE_PREVIEW_FEATURES + preview + true + + diff --git a/CSharp13/ConditionalCompliationSampleClass.cs b/CSharp13/ConditionalCompliationSampleClass.cs new file mode 100644 index 0000000..1944e35 --- /dev/null +++ b/CSharp13/ConditionalCompliationSampleClass.cs @@ -0,0 +1,118 @@ + + +namespace CSharp13.X +{ + namespace Y + { + public static class ConditionalCompliationSampleClass + { + public static C1 Create0() => C1.Create0; + public static C1 Create0O() => C1.Create0; + + public partial class C1 + { + public const double P1 = Math.PI; + public static double P10 => Math.PI; + public static double P11() => Math.PI; + + public static C1 Create0 => new C1(2, 3, 4); + public static C1 Create00() => new C1(2, 3, 4); + public static C1 Create00O() => new C1(2, 3, 4); + public static C1 Create000() => new C1(2, 3, 4); + } +#if NET8_0_OR_GREATER + public partial class C1(int P2, int P3, int P4) + { +#if NET9_0_OR_GREATER +#if DEBUG + //Field-backed property + public int P2 + { + get + { + if (field == 0) + { + //field = 1; + return field; + } + return 1; + } + } = P2; + + public int P3 { get => field; set; } = P3; + public int P4 { get => field; set => field = value; } = P4; +#elif NET9_0_OR_GREATER + + private int _P2 = P2; + private int _P3 = P3; + private int _P4 = P4; + public int P2 + { + get + { + if (_P2 == 0) + { + //_P2 = 1; + return _P2; + } + return _P2; + } + } + public int P3 { get; set; } = P3; + public int P4 { get; set; } = P4; + +#endif +#elif NET8_0_OR_GREATER + private int _P2 = P2; + private int _P3 = P3; + private int _P4 = P4; + public int P2 + { + get + { + if (_P2 == 0) + { + //_P2 = 1; + return _P2; + } + return _P2; + } + } + public int P3 { get => _P3; set => _P3 = value; } + public int P4 { get => _P4; set => _P4 = value; } +#endif + } +#elif NET7_0_OR_GREATER + public partial class C1 + { + private int _P2; + private int _P3; + private int _P4; + + public C1(int P2, int P3, int P4) + { + _P2 = P2; + _P3 = P3; + _P4 = P4; + } + + public int P2 + { + get + { + if (_P2 == 0) + { + //_P2 = 1; + return _P2; + } + return _P2; + } + set => _P2 = value; + } + public int P3 { get => _P3; set => _P3 = value; } + public int P4 { get => _P4; set => _P4 = value; } + } +#endif + } + } +} diff --git a/CSharpAndFSharpConsoleApp.sln b/CSharpAndFSharpConsoleApp.sln index 4f190ff..2fcae50 100644 --- a/CSharpAndFSharpConsoleApp.sln +++ b/CSharpAndFSharpConsoleApp.sln @@ -173,6 +173,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject2", "TestProject EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject3", "TestProject3\TestProject3.csproj", "{466BE363-24D4-46F5-B989-C0E62067ED7E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharp13", "CSharp13\CSharp13.csproj", "{672931EE-F725-4EDD-B7E0-64606930D600}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1033,6 +1035,18 @@ Global {466BE363-24D4-46F5-B989-C0E62067ED7E}.Release|x64.Build.0 = Release|Any CPU {466BE363-24D4-46F5-B989-C0E62067ED7E}.Release|x86.ActiveCfg = Release|Any CPU {466BE363-24D4-46F5-B989-C0E62067ED7E}.Release|x86.Build.0 = Release|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Debug|Any CPU.Build.0 = Debug|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Debug|x64.ActiveCfg = Debug|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Debug|x64.Build.0 = Debug|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Debug|x86.ActiveCfg = Debug|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Debug|x86.Build.0 = Debug|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Release|Any CPU.ActiveCfg = Release|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Release|Any CPU.Build.0 = Release|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Release|x64.ActiveCfg = Release|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Release|x64.Build.0 = Release|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Release|x86.ActiveCfg = Release|Any CPU + {672931EE-F725-4EDD-B7E0-64606930D600}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/README.md b/README.md index 4a24494..838cd6f 100644 --- a/README.md +++ b/README.md @@ -189,4 +189,10 @@ While premature optimization is discouraged, some optimizations may be justified ### Conclusion -In most cases, optimizing before fully understanding the code's behavior and requirements leads to unnecessary complications. Focus on clarity, use profiling to identify real bottlenecks, and optimize incrementally to ensure that your efforts are both necessary and effective. +In most cases, optimizing before fully understanding the code's behavior and requirements leads to unnecessary complications. Focus on clarity, use profiling to identify real bottlenecks, and optimize incrementally to ensure that your efforts are both +necessary and effective. + + +### "MyFeed" Nuget Feed For Sandwich Library + + \ No newline at end of file