Skip to content

Commit

Permalink
use file exclusion for NullabilityInfoExtensions (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Dec 20, 2024
1 parent ceef80f commit f0dd0c5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<NoWarn>$(NoWarn);PolyfillTargetsForNuget</NoWarn>
<TargetFramework>net9.0</TargetFramework>
<PolyGuard>false</PolyGuard>
<PolyNullability>false</PolyNullability>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" />
Expand Down
17 changes: 17 additions & 0 deletions src/NoExtras/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using NUnit.Framework;

[TestFixture]
public class Tests
{
[Test]
public void NoGuard() =>
Assert.IsNull(GetType().Assembly.GetType("Polyfills.Guard"));

[Test]
public void NoNullExtensions()
{
var method = typeof(Polyfill)
.GetMethod("GetNullabilityInfo", BindingFlags.Static | BindingFlags.Public, null, [typeof(MemberInfo)], null);
Assert.IsNull(method);
}
}
9 changes: 0 additions & 9 deletions src/NoGuard/Tests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Polyfill.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoExtras", "NoExtras\NoExtras.csproj", "{4F482296-D4BF-4E56-AF23-351CCEF1B96E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
5 changes: 1 addition & 4 deletions src/Polyfill/Nullability/NullabilityInfoExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// <auto-generated />
#pragma warning disable

#if PolyNullability
#nullable enable

namespace Polyfills;
Expand Down Expand Up @@ -152,6 +151,4 @@ static NullabilityState GetKnownState(string name, NullabilityInfo info)

static bool IsNullable(string name, NullabilityInfo info) =>
GetKnownState(name, info) == NullabilityState.Nullable;
}

#endif
}
9 changes: 3 additions & 6 deletions src/Polyfill/Polyfill.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
<PropertyGroup Condition="$(PolyPublic) == 'true' ">
<DefineConstants>$(DefineConstants);PolyPublic</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(PolyNullability) == 'true' ">
<DefineConstants>$(DefineConstants);PolyNullability</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(PolyGuard) == 'true' ">
<DefineConstants>$(DefineConstants);PolyGuard</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(LowerFramework.StartsWith('netcoreapp2'))">
<DefineConstants>$(DefineConstants);NETCOREAPP2X</DefineConstants>
</PropertyGroup>
Expand Down Expand Up @@ -120,6 +114,9 @@ For example:
<Compile Condition="$(PolyGuard) != 'true' "
Remove="$(MSBuildThisFileDirectory)..\**\Guard\*.cs" />

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

<Compile Update="@(Compile)">
<Visible Condition="%(NuGetItemType) == 'Compile' and
%(NuGetPackageId) == 'Polyfill'">false</Visible>
Expand Down

0 comments on commit f0dd0c5

Please sign in to comment.