// <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", "9.0.14.31522")]
[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.Linq;
using System.Runtime.CompilerServices;
[GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "9.0.14.31522")]
file static class BindingExtensions
{
#region IConfiguration extensions.
/// <summary>Attempts to bind the configuration instance to a new instance of type T.</summary>
[InterceptsLocation(1, "LIIT2NtCS30Qo6t3SdHHwEgEAABQZXJSZXF1ZXN0TG9nQnVmZmVyaW5nQ29uZmlndXJlT3B0aW9ucy5jcw==")] // /_/src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Buffering/PerRequestLogBufferingConfigureOptions.cs(33,37)
public static T? Get<T>(this IConfiguration configuration) => (T?)(GetCore(configuration, typeof(T), configureOptions: null) ?? default(T));
#endregion IConfiguration extensions.
#region IServiceCollection extensions.
/// <summary>Registers a configuration instance which TOptions will bind against.</summary>
[InterceptsLocation(1, "1uep4m6AIRyKDbLjY70MQWUOAABSZXF1ZXN0TGF0ZW5jeVRlbGVtZXRyeVNlcnZpY2VDb2xsZWN0aW9uRXh0ZW5zaW9ucy5jcw==")] // /_/src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Latency/RequestLatencyTelemetryServiceCollectionExtensions.cs(68,10)
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>
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_KeyValuePairStringObject = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Key", "Value" });
private readonly static Lazy<HashSet<string>> s_configKeys_LogBufferingFilterRule = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "CategoryName", "LogLevel", "EventId", "EventName", "Attributes" });
private readonly static Lazy<HashSet<string>> s_configKeys_PerRequestLogBufferingOptions = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "AutoFlushDuration", "MaxLogRecordSizeInBytes", "MaxPerRequestBufferSizeInBytes", "Rules" });
private readonly static Lazy<HashSet<string>> s_configKeys_RequestLatencyTelemetryOptions = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "LatencyDataExportTimeout" });
public static object? GetCore(this IConfiguration configuration, Type type, Action<BinderOptions>? configureOptions)
{
ArgumentNullException.ThrowIfNull(configuration);
BinderOptions? binderOptions = GetBinderOptions(configureOptions);
if (!HasValueOrChildren(configuration))
{
return null;
}
if (type == typeof(global::Microsoft.AspNetCore.Diagnostics.Buffering.PerRequestLogBufferingOptions))
{
var instance = new global::Microsoft.AspNetCore.Diagnostics.Buffering.PerRequestLogBufferingOptions();
BindCore(configuration, ref instance, defaultValueIfNotFound: true, binderOptions);
return instance;
}
throw new NotSupportedException($"Unable to bind to type '{type}': generator did not detect the type as input.");
}
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.AspNetCore.Diagnostics.Latency.RequestLatencyTelemetryOptions))
{
var temp = (global::Microsoft.AspNetCore.Diagnostics.Latency.RequestLatencyTelemetryOptions)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::System.Collections.Generic.KeyValuePair<string, object> instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
ValidateConfigurationKeys(typeof(global::System.Collections.Generic.KeyValuePair<string, object>), s_configKeys_KeyValuePairStringObject, configuration, binderOptions);
}
public static void BindCore(IConfiguration configuration, ref global::System.Collections.Generic.IReadOnlyList<global::System.Collections.Generic.KeyValuePair<string, object>> instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
if (instance is not ICollection<global::System.Collections.Generic.KeyValuePair<string, object>> temp)
{
return;
}
foreach (IConfigurationSection section in configuration.GetChildren())
{
if (!string.IsNullOrEmpty(section.Value) && !section.GetChildren().Any())
{
continue;
}
var value = InitializeKeyValuePairStringObject(section, binderOptions);
BindCore(section, ref value, defaultValueIfNotFound: false, binderOptions);
temp.Add(value);
}
}
public static void BindCore(IConfiguration configuration, ref global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
ValidateConfigurationKeys(typeof(global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule), s_configKeys_LogBufferingFilterRule, configuration, binderOptions);
}
public static void BindCore(IConfiguration configuration, ref global::System.Collections.Generic.IList<global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule> instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
foreach (IConfigurationSection section in configuration.GetChildren())
{
if (!string.IsNullOrEmpty(section.Value) && !section.GetChildren().Any())
{
continue;
}
var value = InitializeLogBufferingFilterRule(section, binderOptions);
BindCore(section, ref value, defaultValueIfNotFound: false, binderOptions);
instance.Add(value);
}
}
public static void BindCore(IConfiguration configuration, ref global::Microsoft.AspNetCore.Diagnostics.Buffering.PerRequestLogBufferingOptions instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
ValidateConfigurationKeys(typeof(global::Microsoft.AspNetCore.Diagnostics.Buffering.PerRequestLogBufferingOptions), s_configKeys_PerRequestLogBufferingOptions, configuration, binderOptions);
if (configuration["AutoFlushDuration"] is string value4 && !string.IsNullOrEmpty(value4))
{
instance.AutoFlushDuration = ParseSystemTimeSpan(value4, configuration.GetSection("AutoFlushDuration").Path);
}
else if (defaultValueIfNotFound)
{
instance.AutoFlushDuration = instance.AutoFlushDuration;
}
if (configuration["MaxLogRecordSizeInBytes"] is string value5 && !string.IsNullOrEmpty(value5))
{
instance.MaxLogRecordSizeInBytes = ParseInt(value5, configuration.GetSection("MaxLogRecordSizeInBytes").Path);
}
else if (defaultValueIfNotFound)
{
instance.MaxLogRecordSizeInBytes = instance.MaxLogRecordSizeInBytes;
}
if (configuration["MaxPerRequestBufferSizeInBytes"] is string value6 && !string.IsNullOrEmpty(value6))
{
instance.MaxPerRequestBufferSizeInBytes = ParseInt(value6, configuration.GetSection("MaxPerRequestBufferSizeInBytes").Path);
}
else if (defaultValueIfNotFound)
{
instance.MaxPerRequestBufferSizeInBytes = instance.MaxPerRequestBufferSizeInBytes;
}
if (AsConfigWithChildren(configuration.GetSection("Rules")) is IConfigurationSection section7)
{
global::System.Collections.Generic.IList<global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule>? temp9 = instance.Rules;
temp9 ??= (global::System.Collections.Generic.IList<global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule>)new List<global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule>();
BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions);
instance.Rules = temp9;
}
else
{
instance.Rules = instance.Rules;
}
}
public static void BindCore(IConfiguration configuration, ref global::Microsoft.AspNetCore.Diagnostics.Latency.RequestLatencyTelemetryOptions instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
{
ValidateConfigurationKeys(typeof(global::Microsoft.AspNetCore.Diagnostics.Latency.RequestLatencyTelemetryOptions), s_configKeys_RequestLatencyTelemetryOptions, configuration, binderOptions);
if (configuration["LatencyDataExportTimeout"] is string value10 && !string.IsNullOrEmpty(value10))
{
instance.LatencyDataExportTimeout = ParseSystemTimeSpan(value10, configuration.GetSection("LatencyDataExportTimeout").Path);
}
else if (defaultValueIfNotFound)
{
instance.LatencyDataExportTimeout = instance.LatencyDataExportTimeout;
}
}
public static global::System.Collections.Generic.KeyValuePair<string, object> InitializeKeyValuePairStringObject(IConfiguration configuration, BinderOptions? binderOptions)
{
if (configuration["Key"] is not string key)
{
throw new InvalidOperationException("Cannot create instance of type 'System.Collections.Generic.KeyValuePair<string, object>' because parameter 'key' has no matching config. Each parameter in the constructor that does not have a default value must have a corresponding config entry.");
}
if (configuration["Value"] is not object value)
{
throw new InvalidOperationException("Cannot create instance of type 'System.Collections.Generic.KeyValuePair<string, object>' because parameter 'value' has no matching config. Each parameter in the constructor that does not have a default value must have a corresponding config entry.");
}
return new global::System.Collections.Generic.KeyValuePair<string, object>(key, value);
}
public static global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule InitializeLogBufferingFilterRule(IConfiguration configuration, BinderOptions? binderOptions)
{
string categoryName = default(string)!;
if (configuration["CategoryName"] is string value11)
{
categoryName = value11;
}
global::Microsoft.Extensions.Logging.LogLevel? logLevel = default(global::Microsoft.Extensions.Logging.LogLevel?);
if (configuration["LogLevel"] is string value12 && !string.IsNullOrEmpty(value12))
{
logLevel = ParseEnum<global::Microsoft.Extensions.Logging.LogLevel>(value12, configuration.GetSection("LogLevel").Path);
}
int? eventId = default(int?);
if (configuration["EventId"] is string value13 && !string.IsNullOrEmpty(value13))
{
eventId = ParseInt(value13, configuration.GetSection("EventId").Path);
}
string eventName = default(string)!;
if (configuration["EventName"] is string value14)
{
eventName = value14;
}
global::System.Collections.Generic.IReadOnlyList<global::System.Collections.Generic.KeyValuePair<string, object>> attributes = default(global::System.Collections.Generic.IReadOnlyList<global::System.Collections.Generic.KeyValuePair<string, object>>)!;
if (AsConfigWithChildren(configuration.GetSection("Attributes")) is IConfigurationSection section15)
{
attributes = (global::System.Collections.Generic.IReadOnlyList<global::System.Collections.Generic.KeyValuePair<string, object>>)new List<global::System.Collections.Generic.KeyValuePair<string, object>>();
BindCore(section15, ref attributes, defaultValueIfNotFound: false, binderOptions);
}
return new global::Microsoft.Extensions.Diagnostics.Buffering.LogBufferingFilterRule(categoryName, logLevel, eventId, eventName, attributes);
}
/// <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 T ParseEnum<T>(string value, string? path) where T : struct
{
try
{
return Enum.Parse<T>(value, ignoreCase: true);
}
catch (Exception exception)
{
throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(T)}'.", 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 at '{path}' to type '{typeof(global::System.TimeSpan)}'.", exception);
}
}
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 at '{path}' to type '{typeof(int)}'.", exception);
}
}
#endregion Core binding extensions.
}
}