<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0-preview.7.24405.7" />

ParameterDefaultValue

static class ParameterDefaultValue
using System; using System.Reflection; using System.Runtime.CompilerServices; namespace Microsoft.Extensions.Internal { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal static class ParameterDefaultValue { public static bool TryGetDefaultValue(ParameterInfo parameter, [System.Runtime.CompilerServices.Nullable(2)] out object defaultValue) { bool tryToGetDefaultValue; bool num = CheckHasDefaultValue(parameter, out tryToGetDefaultValue); defaultValue = null; if (num) { if (tryToGetDefaultValue) defaultValue = parameter.DefaultValue; bool flag = parameter.ParameterType.IsGenericType && parameter.ParameterType.GetGenericTypeDefinition() == typeof(Nullable<>); if (defaultValue == null && parameter.ParameterType.IsValueType && !flag) defaultValue = <TryGetDefaultValue>g__CreateValueType|0_0(parameter.ParameterType); if ((defaultValue != null) & flag) { Type underlyingType = Nullable.GetUnderlyingType(parameter.ParameterType); if (underlyingType != (Type)null && underlyingType.IsEnum) defaultValue = Enum.ToObject(underlyingType, defaultValue); } } return num; } public static bool CheckHasDefaultValue(ParameterInfo parameter, out bool tryToGetDefaultValue) { tryToGetDefaultValue = true; try { return parameter.HasDefaultValue; } catch (FormatException) when (parameter.ParameterType == typeof(DateTime)) { tryToGetDefaultValue = false; return true; } } } }