Skip to content

Commit

Permalink
Use C# preprocessor directives (#1808)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyf19 authored Jul 16, 2022
1 parent 955e823 commit 7ed37da
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 25 deletions.
17 changes: 1 addition & 16 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,7 @@
<AdditionalFiles Include="..\..\.sonarlint\azuread_microsoft-identity-web\CSharp\SonarLint.xml" Link="SonarLint.xml" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
<DefineConstants>$(DefineConstants);DOTNET_50_AND_ABOVE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
<DefineConstants>$(DefineConstants);DOTNET_472</DefineConstants>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net462'">
<DefineConstants>$(DefineConstants);DOTNET_462</DefineConstants>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);DOTNET_STANDARD_20</DefineConstants>
<PropertyGroup Condition="'$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'netstandard2.0'">
<LangVersion>8.0</LangVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ internal string? Container
/// </summary>
public string? Base64EncodedValue { get; set; }

#if DOTNET_462 || DOTNET_STANDARD_20
#if NET462 || NETSTANDARD2_0
/// <summary>
/// Defines where and how to import the private key of an X.509 certificate.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private static X509Certificate2 LoadFromPath(
string certificateFileName,
string? password = null)
{
#if DOTNET_462 || DOTNET_STANDARD_20
#if NET462 || NETSTANDARD2_0
return new X509Certificate2(
certificateFileName,
password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task<HttpResponseMessage> CallWebApiForUserAsync(
{
string error = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

#if DOTNET_50_AND_ABOVE
#if NET5_0_OR_GREATER
throw new HttpRequestException($"{(int)response.StatusCode} {response.StatusCode} {error}", null, response.StatusCode);
#else
throw new HttpRequestException($"{(int)response.StatusCode} {response.StatusCode} {error}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private static StringContent ConvertFromInput<TInput>(TInput input)
{
string error = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

#if DOTNET_50_AND_ABOVE
#if NET5_0_OR_GREATER
throw new HttpRequestException($"{(int)response.StatusCode} {response.StatusCode} {error}", null, response.StatusCode);
#else
throw new HttpRequestException($"{(int)response.StatusCode} {response.StatusCode} {error}");
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.Identity.Web/JwtBearerMergedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void UpdateJwtBearerOptionsFromJwtBearerOptions(JwtBearerOptions j
jwtBearerMergedOptions.Authority = jwtBearerOptions.Authority;
}

#if DOTNET_50_AND_ABOVE
#if NET5_0_OR_GREATER
jwtBearerMergedOptions.AutomaticRefreshInterval = jwtBearerOptions.AutomaticRefreshInterval;
#endif

Expand Down Expand Up @@ -72,7 +72,7 @@ public static void UpdateJwtBearerOptionsFromJwtBearerOptions(JwtBearerOptions j

jwtBearerMergedOptions.IncludeErrorDetails = jwtBearerOptions.IncludeErrorDetails;

#if DOTNET_50_AND_ABOVE
#if NET5_0
jwtBearerMergedOptions.MapInboundClaims = jwtBearerOptions.MapInboundClaims;
#endif

Expand All @@ -81,7 +81,7 @@ public static void UpdateJwtBearerOptionsFromJwtBearerOptions(JwtBearerOptions j
jwtBearerMergedOptions.MetadataAddress = jwtBearerOptions.MetadataAddress;
}

#if DOTNET_50_AND_ABOVE
#if NET5_0
jwtBearerMergedOptions.RefreshInterval = jwtBearerOptions.RefreshInterval;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private static void PopulateOpenIdOptionsFromMergedOptions(
options.DisableTelemetry = mergedOptions.DisableTelemetry;
options.NonceCookie = mergedOptions.NonceCookie;
options.UsePkce = mergedOptions.UsePkce;
#if DOTNET_50_AND_ABOVE
#if NET5_0_OR_GREATER
options.AutomaticRefreshInterval = mergedOptions.AutomaticRefreshInterval;
options.RefreshInterval = mergedOptions.RefreshInterval;
options.MapInboundClaims = mergedOptions.MapInboundClaims;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void TestFromKeyVault(string keyVaultUrl, string certificateName)
Assert.Equal(certificateName, certificateDescription.ReferenceOrValue);
Assert.Equal(certificateName, certificateDescription.KeyVaultCertificateName);
Assert.Equal(keyVaultUrl, certificateDescription.KeyVaultUrl);
#if DOTNET_462
#if NET462
Assert.Equal(X509KeyStorageFlags.MachineKeySet, certificateDescription.X509KeyStorageFlags);
#else
Assert.Equal(X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.EphemeralKeySet, certificateDescription.X509KeyStorageFlags);
Expand Down

0 comments on commit 7ed37da

Please sign in to comment.