// <auto-generated/>
#nullable enable
#pragma warning disable CS0612, CS0618 // Suppress warnings about [Obsolete] member usage in generated code.

namespace System.Runtime.CompilerServices
{
    using System;
    using System.CodeDom.Compiler;

    [GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "42.42.42.42")]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    file sealed class InterceptsLocationAttribute : Attribute
    {
        public InterceptsLocationAttribute(string filePath, int line, int column)
        {
        }
    }
}

namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration
{
    using Microsoft.Extensions.Configuration;
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Runtime.CompilerServices;

    [GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "42.42.42.42")]
    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>
        [InterceptsLocationAttribute(@"src-0.cs", 13, 16)]
        public static void Bind_ProgramMyClass(this IConfiguration configuration, object? obj)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (obj is null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var typedObj = (Program.MyClass)obj;
            BindCore(configuration, ref typedObj, binderOptions: null);
        }
        #endregion IConfiguration extensions.

        #region Core binding extensions.
        private readonly static Lazy<HashSet<string>> s_configKeys_ProgramMyClass = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Prop0", "Prop1", "Prop2", "Prop3", "Prop4", "Prop5", "Prop6", "Prop8", "Prop9", "Prop10", "Prop13", "Prop14", "Prop15", "Prop16", "Prop17", "Prop19", "Prop20", "Prop21", "Prop23", "Prop24", "Prop25", "Prop26", "Prop27", "Prop7", "Prop11", "Prop12", "Prop18", "Prop22" });

        public static void BindCore(IConfiguration configuration, ref Program.MyClass obj, BinderOptions? binderOptions)
        {
            ValidateConfigurationKeys(typeof(Program.MyClass), s_configKeys_ProgramMyClass, configuration, binderOptions);

            if (configuration["Prop0"] is string value0)
            {
                obj.Prop0 = ParseBool(value0, () => configuration.GetSection("Prop0").Path);
            }

            if (configuration["Prop1"] is string value1)
            {
                obj.Prop1 = ParseByte(value1, () => configuration.GetSection("Prop1").Path);
            }

            if (configuration["Prop2"] is string value2)
            {
                obj.Prop2 = ParseSbyte(value2, () => configuration.GetSection("Prop2").Path);
            }

            if (configuration["Prop3"] is string value3)
            {
                obj.Prop3 = ParseChar(value3, () => configuration.GetSection("Prop3").Path);
            }

            if (configuration["Prop4"] is string value4)
            {
                obj.Prop4 = ParseDouble(value4, () => configuration.GetSection("Prop4").Path);
            }

            obj.Prop5 = configuration["Prop5"]!;

            if (configuration["Prop6"] is string value6)
            {
                obj.Prop6 = ParseInt(value6, () => configuration.GetSection("Prop6").Path);
            }

            if (configuration["Prop8"] is string value7)
            {
                obj.Prop8 = ParseShort(value7, () => configuration.GetSection("Prop8").Path);
            }

            if (configuration["Prop9"] is string value8)
            {
                obj.Prop9 = ParseLong(value8, () => configuration.GetSection("Prop9").Path);
            }

            if (configuration["Prop10"] is string value9)
            {
                obj.Prop10 = ParseFloat(value9, () => configuration.GetSection("Prop10").Path);
            }

            if (configuration["Prop13"] is string value10)
            {
                obj.Prop13 = ParseUshort(value10, () => configuration.GetSection("Prop13").Path);
            }

            if (configuration["Prop14"] is string value11)
            {
                obj.Prop14 = ParseUint(value11, () => configuration.GetSection("Prop14").Path);
            }

            if (configuration["Prop15"] is string value12)
            {
                obj.Prop15 = ParseUlong(value12, () => configuration.GetSection("Prop15").Path);
            }

            obj.Prop16 = configuration["Prop16"]!;

            if (configuration["Prop17"] is string value14)
            {
                obj.Prop17 = ParseCultureInfo(value14, () => configuration.GetSection("Prop17").Path);
            }

            if (configuration["Prop19"] is string value15)
            {
                obj.Prop19 = ParseDateTime(value15, () => configuration.GetSection("Prop19").Path);
            }

            if (configuration["Prop20"] is string value16)
            {
                obj.Prop20 = ParseDateTimeOffset(value16, () => configuration.GetSection("Prop20").Path);
            }

            if (configuration["Prop21"] is string value17)
            {
                obj.Prop21 = ParseDecimal(value17, () => configuration.GetSection("Prop21").Path);
            }

            if (configuration["Prop23"] is string value18)
            {
                obj.Prop23 = ParseInt(value18, () => configuration.GetSection("Prop23").Path);
            }

            if (configuration["Prop24"] is string value19)
            {
                obj.Prop24 = ParseDateTime(value19, () => configuration.GetSection("Prop24").Path);
            }

            if (configuration["Prop25"] is string value20)
            {
                obj.Prop25 = ParseUri(value20, () => configuration.GetSection("Prop25").Path);
            }

            if (configuration["Prop26"] is string value21)
            {
                obj.Prop26 = ParseVersion(value21, () => configuration.GetSection("Prop26").Path);
            }

            if (configuration["Prop27"] is string value22)
            {
                obj.Prop27 = ParseEnum<DayOfWeek>(value22, () => configuration.GetSection("Prop27").Path);
            }

            if (configuration["Prop7"] is string value23)
            {
                obj.Prop7 = ParseInt128(value23, () => configuration.GetSection("Prop7").Path);
            }

            if (configuration["Prop11"] is string value24)
            {
                obj.Prop11 = ParseHalf(value24, () => configuration.GetSection("Prop11").Path);
            }

            if (configuration["Prop12"] is string value25)
            {
                obj.Prop12 = ParseUInt128(value25, () => configuration.GetSection("Prop12").Path);
            }

            if (configuration["Prop18"] is string value26)
            {
                obj.Prop18 = ParseDateOnly(value26, () => configuration.GetSection("Prop18").Path);
            }

            if (configuration["Prop22"] is string value27)
            {
                obj.Prop22 = ParseByteArray(value27, () => configuration.GetSection("Prop22").Path);
            }
        }


        /// <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 ParseBool(string value, Func<string?> getPath)
        {
            try
            {
                return bool.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception);
            }
        }

        public static byte ParseByte(string value, Func<string?> getPath)
        {
            try
            {
                return byte.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte)}'.", exception);
            }
        }

        public static sbyte ParseSbyte(string value, Func<string?> getPath)
        {
            try
            {
                return sbyte.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(sbyte)}'.", exception);
            }
        }

        public static char ParseChar(string value, Func<string?> getPath)
        {
            try
            {
                return char.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(char)}'.", exception);
            }
        }

        public static double ParseDouble(string value, Func<string?> getPath)
        {
            try
            {
                return double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception);
            }
        }

        public static int ParseInt(string value, Func<string?> getPath)
        {
            try
            {
                return int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception);
            }
        }

        public static short ParseShort(string value, Func<string?> getPath)
        {
            try
            {
                return short.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(short)}'.", exception);
            }
        }

        public static long ParseLong(string value, Func<string?> getPath)
        {
            try
            {
                return long.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(long)}'.", exception);
            }
        }

        public static float ParseFloat(string value, Func<string?> getPath)
        {
            try
            {
                return float.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception);
            }
        }

        public static ushort ParseUshort(string value, Func<string?> getPath)
        {
            try
            {
                return ushort.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ushort)}'.", exception);
            }
        }

        public static uint ParseUint(string value, Func<string?> getPath)
        {
            try
            {
                return uint.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(uint)}'.", exception);
            }
        }

        public static ulong ParseUlong(string value, Func<string?> getPath)
        {
            try
            {
                return ulong.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ulong)}'.", exception);
            }
        }

        public static CultureInfo ParseCultureInfo(string value, Func<string?> getPath)
        {
            try
            {
                return CultureInfo.GetCultureInfo(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(CultureInfo)}'.", exception);
            }
        }

        public static DateTime ParseDateTime(string value, Func<string?> getPath)
        {
            try
            {
                return DateTime.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(DateTime)}'.", exception);
            }
        }

        public static DateTimeOffset ParseDateTimeOffset(string value, Func<string?> getPath)
        {
            try
            {
                return DateTimeOffset.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(DateTimeOffset)}'.", exception);
            }
        }

        public static decimal ParseDecimal(string value, Func<string?> getPath)
        {
            try
            {
                return decimal.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(decimal)}'.", exception);
            }
        }

        public static TimeSpan ParseTimeSpan(string value, Func<string?> getPath)
        {
            try
            {
                return TimeSpan.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(TimeSpan)}'.", exception);
            }
        }

        public static Guid ParseGuid(string value, Func<string?> getPath)
        {
            try
            {
                return Guid.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(Guid)}'.", exception);
            }
        }

        public static Uri ParseUri(string value, Func<string?> getPath)
        {
            try
            {
                return new Uri(value, UriKind.RelativeOrAbsolute);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(Uri)}'.", exception);
            }
        }

        public static Version ParseVersion(string value, Func<string?> getPath)
        {
            try
            {
                return Version.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(Version)}'.", exception);
            }
        }

        public static T ParseEnum<T>(string value, Func<string?> getPath) where T : struct
        {
            try
            {
                #if NETFRAMEWORK || NETSTANDARD2_0
                    return (T)Enum.Parse(typeof(T), value, ignoreCase: true);
                #else
                    return Enum.Parse<T>(value, ignoreCase: true);
                #endif
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(T)}'.", exception);
            }
        }

        public static Int128 ParseInt128(string value, Func<string?> getPath)
        {
            try
            {
                return Int128.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(Int128)}'.", exception);
            }
        }

        public static Half ParseHalf(string value, Func<string?> getPath)
        {
            try
            {
                return Half.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(Half)}'.", exception);
            }
        }

        public static UInt128 ParseUInt128(string value, Func<string?> getPath)
        {
            try
            {
                return UInt128.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(UInt128)}'.", exception);
            }
        }

        public static DateOnly ParseDateOnly(string value, Func<string?> getPath)
        {
            try
            {
                return DateOnly.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(DateOnly)}'.", exception);
            }
        }

        public static TimeOnly ParseTimeOnly(string value, Func<string?> getPath)
        {
            try
            {
                return TimeOnly.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(TimeOnly)}'.", exception);
            }
        }

        public static byte[] ParseByteArray(string value, Func<string?> getPath)
        {
            try
            {
                return Convert.FromBase64String(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte[])}'.", exception);
            }
        }
        #endregion Core binding extensions.
    }
}
