From 8a0181df01b4fd21d5f44290ba13781c4b540e06 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 20 Dec 2024 22:18:00 +1100 Subject: [PATCH] use file exclusions for guards --- src/NoGuard/NoGuard.csproj | 15 +++++++++++++++ src/NoGuard/Tests.cs | 9 +++++++++ src/Polyfill.sln | 6 ++++++ src/Polyfill/{ => Guard}/Guard.cs | 5 +---- src/Polyfill/{ => Guard}/Guard_NotEmpty.cs | 5 +---- src/Polyfill/{ => Guard}/Guard_NotNull.cs | 5 +---- src/Polyfill/{ => Guard}/Guard_NotNullOrEmpty.cs | 6 ++---- .../{ => Guard}/Guard_NotNullOrWhiteSpace.cs | 5 +---- src/Polyfill/{ => Guard}/Guard_NotWhiteSpace.cs | 5 +---- src/Polyfill/Polyfill.targets | 4 ++++ src/TestIncludes.targets | 3 +++ 11 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 src/NoGuard/NoGuard.csproj create mode 100644 src/NoGuard/Tests.cs rename src/Polyfill/{ => Guard}/Guard.cs (97%) rename src/Polyfill/{ => Guard}/Guard_NotEmpty.cs (99%) rename src/Polyfill/{ => Guard}/Guard_NotNull.cs (97%) rename src/Polyfill/{ => Guard}/Guard_NotNullOrEmpty.cs (99%) rename src/Polyfill/{ => Guard}/Guard_NotNullOrWhiteSpace.cs (99%) rename src/Polyfill/{ => Guard}/Guard_NotWhiteSpace.cs (99%) diff --git a/src/NoGuard/NoGuard.csproj b/src/NoGuard/NoGuard.csproj new file mode 100644 index 00000000..eb5f17fe --- /dev/null +++ b/src/NoGuard/NoGuard.csproj @@ -0,0 +1,15 @@ + + + $(NoWarn);PolyfillTargetsForNuget + net9.0 + false + + + + + + + + + + \ No newline at end of file diff --git a/src/NoGuard/Tests.cs b/src/NoGuard/Tests.cs new file mode 100644 index 00000000..b38e89b0 --- /dev/null +++ b/src/NoGuard/Tests.cs @@ -0,0 +1,9 @@ +using NUnit.Framework; + +[TestFixture] +public class Tests +{ + [Test] + public void NoGuard() => + Assert.IsNull(GetType().Assembly.GetType("Polyfills.Guard")); +} \ No newline at end of file diff --git a/src/Polyfill.sln b/src/Polyfill.sln index 7cef8460..b4d896b8 100644 --- a/src/Polyfill.sln +++ b/src/Polyfill.sln @@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiBuilderTests", "ApiBuild EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeOnlyValueTuple", "ConsumeOnlyValueTuple\ConsumeOnlyValueTuple.csproj", "{2FE1429A-68B0-4C71-B1ED-D371C72DAD0E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoGuard", "NoGuard\NoGuard.csproj", "{4F482296-D4BF-4E56-AF23-351CCEF1B96E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -137,6 +139,10 @@ Global {2FE1429A-68B0-4C71-B1ED-D371C72DAD0E}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FE1429A-68B0-4C71-B1ED-D371C72DAD0E}.Release|Any CPU.ActiveCfg = Release|Any CPU {2FE1429A-68B0-4C71-B1ED-D371C72DAD0E}.Release|Any CPU.Build.0 = Release|Any CPU + {4F482296-D4BF-4E56-AF23-351CCEF1B96E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F482296-D4BF-4E56-AF23-351CCEF1B96E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F482296-D4BF-4E56-AF23-351CCEF1B96E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F482296-D4BF-4E56-AF23-351CCEF1B96E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Polyfill/Guard.cs b/src/Polyfill/Guard/Guard.cs similarity index 97% rename from src/Polyfill/Guard.cs rename to src/Polyfill/Guard/Guard.cs index 3314f984..c2e15bd6 100644 --- a/src/Polyfill/Guard.cs +++ b/src/Polyfill/Guard/Guard.cs @@ -6,8 +6,6 @@ namespace Polyfills; #pragma warning disable -#if PolyGuard - using System; using System.IO; using System.Diagnostics; @@ -38,5 +36,4 @@ public static void DirectoryExists(string path, [CallerArgumentExpression("path" throw new ArgumentException($"Directory not found. Path: {path}", argumentName); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Polyfill/Guard_NotEmpty.cs b/src/Polyfill/Guard/Guard_NotEmpty.cs similarity index 99% rename from src/Polyfill/Guard_NotEmpty.cs rename to src/Polyfill/Guard/Guard_NotEmpty.cs index 60267241..167b6e51 100644 --- a/src/Polyfill/Guard_NotEmpty.cs +++ b/src/Polyfill/Guard/Guard_NotEmpty.cs @@ -3,8 +3,6 @@ namespace Polyfills; -#if PolyGuard - using System.Runtime.CompilerServices; using System; using System.Collections; @@ -143,5 +141,4 @@ public static void NotEmpty( } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Polyfill/Guard_NotNull.cs b/src/Polyfill/Guard/Guard_NotNull.cs similarity index 97% rename from src/Polyfill/Guard_NotNull.cs rename to src/Polyfill/Guard/Guard_NotNull.cs index 3ded2103..2f380c3a 100644 --- a/src/Polyfill/Guard_NotNull.cs +++ b/src/Polyfill/Guard/Guard_NotNull.cs @@ -3,8 +3,6 @@ namespace Polyfills; -#if PolyGuard - using System; using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; @@ -38,5 +36,4 @@ public static string NotNull( return argument; } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Polyfill/Guard_NotNullOrEmpty.cs b/src/Polyfill/Guard/Guard_NotNullOrEmpty.cs similarity index 99% rename from src/Polyfill/Guard_NotNullOrEmpty.cs rename to src/Polyfill/Guard/Guard_NotNullOrEmpty.cs index 3b1ae884..c50f2b1f 100644 --- a/src/Polyfill/Guard_NotNullOrEmpty.cs +++ b/src/Polyfill/Guard/Guard_NotNullOrEmpty.cs @@ -1,9 +1,8 @@ // #pragma warning disable -#if PolyGuard - namespace Polyfills; + using System.Runtime.CompilerServices; using System; using System.Collections; @@ -104,5 +103,4 @@ public static ReadOnlyMemory NotNullOrEmpty( throw new ArgumentException("Argument cannot be whitespace.", argumentName); } #endif -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Polyfill/Guard_NotNullOrWhiteSpace.cs b/src/Polyfill/Guard/Guard_NotNullOrWhiteSpace.cs similarity index 99% rename from src/Polyfill/Guard_NotNullOrWhiteSpace.cs rename to src/Polyfill/Guard/Guard_NotNullOrWhiteSpace.cs index 48b651dc..fc934f6b 100644 --- a/src/Polyfill/Guard_NotNullOrWhiteSpace.cs +++ b/src/Polyfill/Guard/Guard_NotNullOrWhiteSpace.cs @@ -1,8 +1,6 @@ // #pragma warning disable -#if PolyGuard - namespace Polyfills; using System.Runtime.CompilerServices; @@ -96,5 +94,4 @@ public static ReadOnlyMemory NotNullOrWhiteSpace( throw new ArgumentException("Argument cannot be whitespace.", argumentName); } #endif -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Polyfill/Guard_NotWhiteSpace.cs b/src/Polyfill/Guard/Guard_NotWhiteSpace.cs similarity index 99% rename from src/Polyfill/Guard_NotWhiteSpace.cs rename to src/Polyfill/Guard/Guard_NotWhiteSpace.cs index 4026a987..40068526 100644 --- a/src/Polyfill/Guard_NotWhiteSpace.cs +++ b/src/Polyfill/Guard/Guard_NotWhiteSpace.cs @@ -1,8 +1,6 @@ // #pragma warning disable -#if PolyGuard - namespace Polyfills; using System.Runtime.CompilerServices; @@ -134,5 +132,4 @@ public static void NotWhiteSpace( throw new ArgumentException("Argument cannot be whitespace.", argumentName); } #endif -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Polyfill/Polyfill.targets b/src/Polyfill/Polyfill.targets index 38935e7b..324fee32 100644 --- a/src/Polyfill/Polyfill.targets +++ b/src/Polyfill/Polyfill.targets @@ -116,6 +116,10 @@ For example: + + + false diff --git a/src/TestIncludes.targets b/src/TestIncludes.targets index 2deb26d8..2297e3a8 100644 --- a/src/TestIncludes.targets +++ b/src/TestIncludes.targets @@ -3,6 +3,9 @@ Pollyfill\%(Filename).cs + + Pollyfill\Guard\%(RecursiveDir)%(Filename).cs + Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs