diff --git a/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.cs b/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.cs index f69b52220f355..535d8ff3679a7 100644 --- a/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.cs +++ b/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.cs @@ -15,27 +15,13 @@ namespace Microsoft.Extensions.Internal { - internal static class ParameterDefaultValue + internal static partial class ParameterDefaultValue { public static bool TryGetDefaultValue(ParameterInfo parameter, out object? defaultValue) { - bool hasDefaultValue; - bool tryToGetDefaultValue = true; + bool hasDefaultValue = CheckHasDefaultValue(parameter, out bool tryToGetDefaultValue); defaultValue = null; - try - { - hasDefaultValue = 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 - hasDefaultValue = true; - tryToGetDefaultValue = false; - } - if (hasDefaultValue) { if (tryToGetDefaultValue) diff --git a/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netcoreapp.cs b/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netcoreapp.cs new file mode 100644 index 0000000000000..484fc384df1f3 --- /dev/null +++ b/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netcoreapp.cs @@ -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; + } + } +} diff --git a/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netstandard.cs b/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netstandard.cs new file mode 100644 index 0000000000000..21e9fdf849a9f --- /dev/null +++ b/src/libraries/Common/src/Extensions/ParameterDefaultValue/ParameterDefaultValue.netstandard.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs index 94bbfdb2a4533..99ef9aec6b3ae 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs @@ -98,10 +98,10 @@ public static ObjectFactory CreateFactory( ParameterExpression? argumentArray = Expression.Parameter(typeof(object[]), "argumentArray"); Expression? factoryExpressionBody = BuildFactoryExpression(constructor, parameterMap, provider, argumentArray); - var factoryLambda = Expression.Lambda>( + var factoryLambda = Expression.Lambda>( factoryExpressionBody, provider, argumentArray); - Func? result = factoryLambda.Compile(); + Func? result = factoryLambda.Compile(); return result.Invoke; } diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/Microsoft.Extensions.DependencyInjection.Abstractions.csproj b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/Microsoft.Extensions.DependencyInjection.Abstractions.csproj index c6eff6edf2d49..b275c71c780c7 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/Microsoft.Extensions.DependencyInjection.Abstractions.csproj +++ b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/Microsoft.Extensions.DependencyInjection.Abstractions.csproj @@ -1,18 +1,30 @@ - netstandard2.1;netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.1;netstandard2.0;net461 true enable Abstractions for dependency injection. Commonly Used Types: Microsoft.Extensions.DependencyInjection.IServiceCollection + + false + + + + + + + + diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj b/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj index 9884fdceeaecb..b93c0a8e61e66 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj @@ -1,13 +1,15 @@ - netstandard2.1;netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.1;netstandard2.0;net461 False Annotations $(NoWarn);CP0001 Default implementation of dependency injection for Microsoft.Extensions.DependencyInjection. + + false @@ -17,21 +19,29 @@ $(DefineConstants);SAVE_ASSEMBLIES + + + + + + + + + + + + - - - - - -