Skip to content

Commit

Permalink
use file exclusions for guards
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 20, 2024
1 parent 04a6de4 commit 8a0181d
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 24 deletions.
15 changes: 15 additions & 0 deletions src/NoGuard/NoGuard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoWarn>$(NoWarn);PolyfillTargetsForNuget</NoWarn>
<TargetFramework>net9.0</TargetFramework>
<PolyGuard>false</PolyGuard>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
</ItemGroup>
<Import Project="$(SolutionDir)\TestIncludes.targets" />
<Import Project="$(SolutionDir)\Polyfill\Polyfill.targets" />
</Project>
9 changes: 9 additions & 0 deletions src/NoGuard/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using NUnit.Framework;

[TestFixture]
public class Tests
{
[Test]
public void NoGuard() =>
Assert.IsNull(GetType().Assembly.GetType("Polyfills.Guard"));
}
6 changes: 6 additions & 0 deletions src/Polyfill.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Polyfill/Guard.cs → src/Polyfill/Guard/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Polyfills;

#pragma warning disable

#if PolyGuard

using System;
using System.IO;
using System.Diagnostics;
Expand Down Expand Up @@ -38,5 +36,4 @@ public static void DirectoryExists(string path, [CallerArgumentExpression("path"
throw new ArgumentException($"Directory not found. Path: {path}", argumentName);
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Polyfills;

#if PolyGuard

using System.Runtime.CompilerServices;
using System;
using System.Collections;
Expand Down Expand Up @@ -143,5 +141,4 @@ public static void NotEmpty<T>(
}
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Polyfills;

#if PolyGuard

using System;
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -38,5 +36,4 @@ public static string NotNull(

return argument;
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// <auto-generated />
#pragma warning disable

#if PolyGuard

namespace Polyfills;

using System.Runtime.CompilerServices;
using System;
using System.Collections;
Expand Down Expand Up @@ -104,5 +103,4 @@ public static ReadOnlyMemory<char> NotNullOrEmpty(
throw new ArgumentException("Argument cannot be whitespace.", argumentName);
}
#endif
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// <auto-generated />
#pragma warning disable

#if PolyGuard

namespace Polyfills;

using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -96,5 +94,4 @@ public static ReadOnlyMemory<char> NotNullOrWhiteSpace(
throw new ArgumentException("Argument cannot be whitespace.", argumentName);
}
#endif
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// <auto-generated />
#pragma warning disable

#if PolyGuard

namespace Polyfills;

using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -134,5 +132,4 @@ public static void NotWhiteSpace(
throw new ArgumentException("Argument cannot be whitespace.", argumentName);
}
#endif
}
#endif
}
4 changes: 4 additions & 0 deletions src/Polyfill/Polyfill.targets
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ For example:
</PropertyGroup>
</Target>
<ItemGroup>

<Compile Condition="$(PolyGuard) != 'true' "
Remove="$(MSBuildThisFileDirectory)..\**\Guard\*.cs" />

<Compile Update="@(Compile)">
<Visible Condition="%(NuGetItemType) == 'Compile' and
%(NuGetPackageId) == 'Polyfill'">false</Visible>
Expand Down
3 changes: 3 additions & 0 deletions src/TestIncludes.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<Compile Include="$(SolutionDir)Polyfill\*.cs">
<Link>Pollyfill\%(Filename).cs</Link>
</Compile>
<Compile Include="$(SolutionDir)Polyfill\Guard\*.cs">
<Link>Pollyfill\Guard\%(RecursiveDir)%(Filename).cs</Link>
</Compile>
<Compile Include="$(SolutionDir)Polyfill\Nullable\*.cs">
<Link>Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs</Link>
</Compile>
Expand Down

0 comments on commit 8a0181d

Please sign in to comment.