Skip to content

Commit

Permalink
Add ConditionalCompliationSampleClass.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdlop committed Dec 20, 2024
1 parent 5cfad52 commit 9eb4d55
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
15 changes: 15 additions & 0 deletions CSharp13/CSharp13.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>


<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>USE_PREVIEW_FEATURES</DefineConstants>
<LangVersion>preview</LangVersion>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>
</Project>
118 changes: 118 additions & 0 deletions CSharp13/ConditionalCompliationSampleClass.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
}
14 changes: 14 additions & 0 deletions CSharpAndFSharpConsoleApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<https://pkgs.dev.azure.com/ray810815/Sandwich/_packaging/MyFeed/nuget/v3/index.json>

0 comments on commit 9eb4d55

Please sign in to comment.