// <auto-generated/>
#nullable enable annotations
#nullable disable warnings
// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618
namespace System.Runtime.CompilerServices
{
using System;
using System.CodeDom.Compiler;
[GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "10.0.14.32716")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(int version, string data)
{
}
}
}
namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration
{
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
[GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "10.0.14.32716")]
file static class BindingExtensions
{
#region IConfiguration extensions.
/// <summary>Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively.</summary>
[InterceptsLocation(1, "xYaa/InVoTWA9EvFW0Lgmk8GAABLdWJlcm5ldGVzUHJvYmVzRXh0ZW5zaW9ucy5jcw==")] // /_/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesExtensions.cs(36,58)
public static void Bind_KubernetesProbesOptions(this IConfiguration configuration, object? instance)
{
ArgumentNullException.ThrowIfNull(configuration);
if (instance is null)
{
return;
}
var typedObj = (global::Microsoft.Extensions.Diagnostics.Probes.KubernetesProbesOptions)instance;
BindCore(configuration, ref typedObj, defaultValueIfNotFound: false, binderOptions: null);
}
#endregion IConfiguration extensions.
#region IServiceCollection extensions.
/// <summary>Registers a configuration instance which TOptions will bind against.</summary>
[InterceptsLocation(1, "MQHjUidMVt95cLF1hKas8HISAABUY3BFbmRwb2ludFByb2Jlc0V4dGVuc2lvbnMuY3M=")] // /_/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesExtensions.cs(112,22)
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, IConfiguration config) where TOptions : class
{
return Configure<TOptions>(services, string.Empty, config, configureOptions: null);
}
/// <summary>Registers a configuration instance which TOptions will bind against.</summary>
[InterceptsLocation(1, "MQHjUidMVt95cLF1hKas8A4WAABUY3BFbmRwb2ludFByb2Jlc0V4dGVuc2lvbnMuY3M=")] // /_/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesExtensions.cs(133,22)
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, string? name, IConfiguration config) where TOptions : class
{
return Configure<TOptions>(services, name, config, configureOptions: null);
}
/// <summary>Registers a configuration instance which TOptions will bind against.</summary>
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, string? name, IConfiguration config, Action<BinderOptions>? configureOptions) where TOptions : class
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(config);
OptionsServiceCollectionExtensions.AddOptions(services);
services.AddSingleton<IOptionsChangeTokenSource<TOptions>>(new ConfigurationChangeTokenSource<TOptions>(name, config));
return services.AddSingleton<IConfigureOptions<TOptions>>(new ConfigureNamedOptions<TOptions>(name, instance => BindCoreMain(config, instance, typeof(TOptions), configureOptions)));
}
#endregion IServiceCollection extensions.
#region Core binding extensions.
private readonly static Lazy<HashSet<string>> s_configKeys_TcpEndpointProbesOptions = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "TcpPort", "MaxPendingConnections", "HealthAssessmentPeriod" });
private readonly static Lazy<HashSet<string>> s_configKeys_KubernetesProbesOptions = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "LivenessProbe", "StartupProbe", "ReadinessProbe" });
public static void BindCoreMain(IConfiguration configuration, object instance, Type type, Action<BinderOptions>? configureOptions)
{
if (instance is null)
{
return;
}
if (!HasValueOrChildren(configuration))
{
return;
}
BinderOptions? binderOptions = GetBinderOptions(configureOptions);
if (type == typeof(global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions))
{
var temp = (global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions)instance;
BindCore(configuration, ref temp, defaultValueIfNotFound: false, binderOptions);
return;
}
throw new NotSupportedException($"Unable to bind to type '{type}': generator did not detect the type as input.");
}
public static void BindCore(IConfiguration configuration, ref global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
ValidateConfigurationKeys(typeof(global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions), s_configKeys_TcpEndpointProbesOptions, configuration, binderOptions);
if (TryGetConfigurationValue(configuration, key: "TcpPort", out string? value1))
{
if (!string.IsNullOrEmpty(value1))
{
instance.TcpPort = ParseInt(value1, configuration.GetSection("TcpPort").Path);
}
}
else if (defaultValueIfNotFound)
{
instance.TcpPort = instance.TcpPort;
}
if (TryGetConfigurationValue(configuration, key: "MaxPendingConnections", out string? value2))
{
if (!string.IsNullOrEmpty(value2))
{
instance.MaxPendingConnections = ParseInt(value2, configuration.GetSection("MaxPendingConnections").Path);
}
}
else if (defaultValueIfNotFound)
{
instance.MaxPendingConnections = instance.MaxPendingConnections;
}
if (TryGetConfigurationValue(configuration, key: "HealthAssessmentPeriod", out string? value3))
{
if (!string.IsNullOrEmpty(value3))
{
instance.HealthAssessmentPeriod = ParseSystemTimeSpan(value3, configuration.GetSection("HealthAssessmentPeriod").Path);
}
}
else if (defaultValueIfNotFound)
{
instance.HealthAssessmentPeriod = instance.HealthAssessmentPeriod;
}
}
public static void BindCore(IConfiguration configuration, ref global::Microsoft.Extensions.Diagnostics.Probes.KubernetesProbesOptions instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
ValidateConfigurationKeys(typeof(global::Microsoft.Extensions.Diagnostics.Probes.KubernetesProbesOptions), s_configKeys_KubernetesProbesOptions, configuration, binderOptions);
var value4 = configuration.GetSection("LivenessProbe");
if (AsConfigWithChildren(value4) is IConfigurationSection section5)
{
global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions? temp7 = instance.LivenessProbe;
temp7 ??= new global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions();
BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions);
instance.LivenessProbe = temp7;
}
else
{
instance.LivenessProbe = instance.LivenessProbe;
}
var value8 = configuration.GetSection("StartupProbe");
if (AsConfigWithChildren(value8) is IConfigurationSection section9)
{
global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions? temp11 = instance.StartupProbe;
temp11 ??= new global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions();
BindCore(section9, ref temp11, defaultValueIfNotFound: false, binderOptions);
instance.StartupProbe = temp11;
}
else
{
instance.StartupProbe = instance.StartupProbe;
}
var value12 = configuration.GetSection("ReadinessProbe");
if (AsConfigWithChildren(value12) is IConfigurationSection section13)
{
global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions? temp15 = instance.ReadinessProbe;
temp15 ??= new global::Microsoft.Extensions.Diagnostics.Probes.TcpEndpointProbesOptions();
BindCore(section13, ref temp15, defaultValueIfNotFound: false, binderOptions);
instance.ReadinessProbe = temp15;
}
else
{
instance.ReadinessProbe = instance.ReadinessProbe;
}
}
/// <summary>Tries to get the configuration value for the specified key.</summary>
public static bool TryGetConfigurationValue(IConfiguration configuration, string key, out string? value)
{
if (configuration is ConfigurationSection section)
{
return section.TryGetValue(key, out value);
}
value = key != null ? configuration[key] : configuration is IConfigurationSection sec ? sec.Value : null;
return value != null;
}
/// <summary>If required by the binder options, validates that there are no unknown keys in the input configuration object.</summary>
public static void ValidateConfigurationKeys(Type type, Lazy<HashSet<string>> keys, IConfiguration configuration, BinderOptions? binderOptions)
{
if (binderOptions?.ErrorOnUnknownConfiguration is true)
{
List<string>? temp = null;
foreach (IConfigurationSection section in configuration.GetChildren())
{
if (!keys.Value.Contains(section.Key))
{
(temp ??= new List<string>()).Add($"'{section.Key}'");
}
}
if (temp is not null)
{
throw new InvalidOperationException($"'ErrorOnUnknownConfiguration' was set on the provided BinderOptions, but the following properties were not found on the instance of {type}: {string.Join(", ", temp)}");
}
}
}
public static bool HasValueOrChildren(IConfiguration configuration)
{
if ((configuration as IConfigurationSection)?.Value is not null)
{
return true;
}
return AsConfigWithChildren(configuration) is not null;
}
public static IConfiguration? AsConfigWithChildren(IConfiguration configuration)
{
foreach (IConfigurationSection _ in configuration.GetChildren())
{
return configuration;
}
return null;
}
public static BinderOptions? GetBinderOptions(Action<BinderOptions>? configureOptions)
{
if (configureOptions is null)
{
return null;
}
BinderOptions binderOptions = new();
configureOptions(binderOptions);
if (binderOptions.BindNonPublicProperties)
{
throw new NotSupportedException($"The configuration binding source generator does not support 'BinderOptions.BindNonPublicProperties'.");
}
return binderOptions;
}
public static int ParseInt(string value, string? path)
{
try
{
return int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
}
catch (Exception exception)
{
throw new InvalidOperationException($"Failed to convert configuration value '{value ?? "null"}' at '{path}' to type '{typeof(int)}'.", exception);
}
}
public static global::System.TimeSpan ParseSystemTimeSpan(string value, string? path)
{
try
{
return global::System.TimeSpan.Parse(value, CultureInfo.InvariantCulture);
}
catch (Exception exception)
{
throw new InvalidOperationException($"Failed to convert configuration value '{value ?? "null"}' at '{path}' to type '{typeof(global::System.TimeSpan)}'.", exception);
}
}
#endregion Core binding extensions.
}
}