-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ParameterDefaultValue.TryGetDefaultValue bitcode compliant (#56324)
* Make ParameterDefaultValue.TryGetDefaultValue bitcode compliant Fixes #50439 * code cleanup * enable nullable for netcoreapp * move to second property group * Apply PR feedback * Apply PR feedback * code cleanup - remove ifdef * Update src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com> Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
- Loading branch information
1 parent
7060801
commit 222c613
Showing
6 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netcoreapp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Microsoft.Extensions.Internal | ||
{ | ||
internal static partial class ParameterDefaultValue | ||
{ | ||
public static bool CheckHasDefaultValue(ParameterInfo parameter, out bool tryToGetDefaultValue) | ||
{ | ||
tryToGetDefaultValue = true; | ||
return parameter.HasDefaultValue; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ibraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netstandard.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Microsoft.Extensions.Internal | ||
{ | ||
internal static partial class ParameterDefaultValue | ||
{ | ||
public static bool CheckHasDefaultValue(ParameterInfo parameter, out bool tryToGetDefaultValue) | ||
{ | ||
tryToGetDefaultValue = true; | ||
try | ||
{ | ||
return parameter.HasDefaultValue; | ||
} | ||
catch (FormatException) when (parameter.ParameterType == typeof(DateTime)) | ||
{ | ||
// Workaround for https://github.com/dotnet/runtime/issues/18844 | ||
// If HasDefaultValue throws FormatException for DateTime | ||
// we expect it to have default value | ||
tryToGetDefaultValue = false; | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
...cyInjection.Abstractions/src/Microsoft.Extensions.DependencyInjection.Abstractions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters