diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs index 49b7dd144c0e9..179b7a65b78d2 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs @@ -569,11 +569,11 @@ private void EmitGetBinderOptionsHelper() private void EmitEnumParseMethod() { - string exceptionArg1 = string.Format(ExceptionMessages.FailedBinding, $"{{{Identifier.getPath}()}}", $"{{typeof(T)}}"); + string exceptionArg1 = string.Format(ExceptionMessages.FailedBinding, $"{{{Identifier.path}}}", $"{{typeof(T)}}"); string parseEnumCall = _emitGenericParseEnum ? "Enum.Parse(value, ignoreCase: true)" : "(T)Enum.Parse(typeof(T), value, ignoreCase: true)"; _writer.WriteLine($$""" - public static T ParseEnum(string value, Func getPath) where T : struct + public static T ParseEnum(string value, string? path) where T : struct { try { @@ -639,9 +639,9 @@ private void EmitPrimitiveParseMethod(ParsableFromStringSpec type) } } - string exceptionArg1 = string.Format(ExceptionMessages.FailedBinding, $"{{{Identifier.getPath}()}}", $"{{typeof({typeFQN})}}"); + string exceptionArg1 = string.Format(ExceptionMessages.FailedBinding, $"{{{Identifier.path}}}", $"{{typeof({typeFQN})}}"); - EmitStartBlock($"public static {typeFQN} {TypeIndex.GetParseMethodName(type)}(string {Identifier.value}, Func {Identifier.getPath})"); + EmitStartBlock($"public static {typeFQN} {TypeIndex.GetParseMethodName(type)}(string {Identifier.value}, string? {Identifier.path})"); EmitEndBlock($$""" try { @@ -1084,8 +1084,8 @@ private void EmitBindingLogic( string parsedValueExpr = typeKind switch { StringParsableTypeKind.AssignFromSectionValue => stringValueToParse_Expr, - StringParsableTypeKind.Enum => $"ParseEnum<{type.TypeRef.FullyQualifiedName}>({stringValueToParse_Expr}, () => {sectionPathExpr})", - _ => $"{TypeIndex.GetParseMethodName(type)}({stringValueToParse_Expr}, () => {sectionPathExpr})", + StringParsableTypeKind.Enum => $"ParseEnum<{type.TypeRef.FullyQualifiedName}>({stringValueToParse_Expr}, {sectionPathExpr})", + _ => $"{TypeIndex.GetParseMethodName(type)}({stringValueToParse_Expr}, {sectionPathExpr})", }; if (!checkForNullSectionValue) diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/Helpers.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/Helpers.cs index 3a0200d684307..cf56aae81ba47 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/Helpers.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/Helpers.cs @@ -71,12 +71,12 @@ private static class Identifier public const string element = nameof(element); public const string enumValue = nameof(enumValue); public const string exception = nameof(exception); - public const string getPath = nameof(getPath); public const string key = nameof(key); public const string name = nameof(name); public const string instance = nameof(instance); public const string optionsBuilder = nameof(optionsBuilder); public const string originalCount = nameof(originalCount); + public const string path = nameof(path); public const string section = nameof(section); public const string sectionKey = nameof(sectionKey); public const string services = nameof(services); diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Collections.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Collections.generated.txt index a03d4c855c399..54c0b42cc3f05 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Collections.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Collections.generated.txt @@ -73,7 +73,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance[section.Key] = ParseInt(value, () => section.Path); + instance[section.Key] = ParseInt(value, section.Path); } } } @@ -100,7 +100,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp.Add(ParseInt(value, () => section.Path)); + temp.Add(ParseInt(value, section.Path)); } } } @@ -116,7 +116,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp[section.Key] = ParseInt(value, () => section.Path); + temp[section.Key] = ParseInt(value, section.Path); } } } @@ -217,7 +217,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -225,7 +225,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind.generated.txt index 8cb6fa53a52eb..1b64f116d2508 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind.generated.txt @@ -98,7 +98,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -137,7 +137,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -219,7 +219,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -227,7 +227,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance.generated.txt index 392f067b9c364..c80e48e19e158 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance.generated.txt @@ -62,7 +62,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -101,7 +101,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -165,7 +165,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -173,7 +173,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt index 35f4495fe0c18..efb7616cd1b90 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt @@ -62,7 +62,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -101,7 +101,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -183,7 +183,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -191,7 +191,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Key_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Key_Instance.generated.txt index 6373c432f5240..c8f211fe59de7 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Key_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Bind_Key_Instance.generated.txt @@ -62,7 +62,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -101,7 +101,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -165,7 +165,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -173,7 +173,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get.generated.txt index b51fefddba98a..c9b1f23de26c7 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get.generated.txt @@ -91,7 +91,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -104,7 +104,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp2.Add(ParseInt(value, () => section.Path)); + temp2.Add(ParseInt(value, section.Path)); } } @@ -135,7 +135,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -173,7 +173,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value14) { - instance.MyInt = ParseInt(value14, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value14, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -240,7 +240,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -248,7 +248,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue.generated.txt index e6fb4b5166ed8..7466c543a85e5 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue.generated.txt @@ -67,25 +67,25 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(int)) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } else if (type == typeof(bool?)) { - return ParseBool(value, () => section.Path); + return ParseBool(value, section.Path); } else if (type == typeof(byte[])) { - return ParseByteArray(value, () => section.Path); + return ParseByteArray(value, section.Path); } else if (type == typeof(global::System.Globalization.CultureInfo)) { - return ParseSystemGlobalizationCultureInfo(value, () => section.Path); + return ParseSystemGlobalizationCultureInfo(value, section.Path); } return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -93,11 +93,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static bool ParseBool(string value, Func getPath) + public static bool ParseBool(string value, string? path) { try { @@ -105,11 +105,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(bool)}'.", exception); } } - public static byte[] ParseByteArray(string value, Func getPath) + public static byte[] ParseByteArray(string value, string? path) { try { @@ -117,11 +117,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte[])}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(byte[])}'.", exception); } } - public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func getPath) + public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, string? path) { try { @@ -129,7 +129,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key.generated.txt index 273df87c8e809..4f822c0f75d64 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key.generated.txt @@ -55,13 +55,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(int)) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt index b3d91eb6b49e8..f7fe233d3569c 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt @@ -55,13 +55,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(int)) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt index b8c1c5b138191..644f3ce18e82f 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt @@ -55,13 +55,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(bool?)) { - return ParseBool(value, () => section.Path); + return ParseBool(value, section.Path); } return null; } - public static bool ParseBool(string value, Func getPath) + public static bool ParseBool(string value, string? path) { try { @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(bool)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt index f93fb114275fe..ebf24068b77fa 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt @@ -55,13 +55,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(global::System.Globalization.CultureInfo)) { - return ParseSystemGlobalizationCultureInfo(value, () => section.Path); + return ParseSystemGlobalizationCultureInfo(value, section.Path); } return null; } - public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func getPath) + public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, string? path) { try { @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_PrimitivesOnly.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_PrimitivesOnly.generated.txt index 446bf43866a38..29d5a787ef3be 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_PrimitivesOnly.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_PrimitivesOnly.generated.txt @@ -73,7 +73,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } if (section.Value is string value) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } } else if (type == typeof(string)) @@ -92,7 +92,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } if (section.Value is string value) { - return ParseFloat(value, () => section.Path); + return ParseFloat(value, section.Path); } } else if (type == typeof(double)) @@ -103,7 +103,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } if (section.Value is string value) { - return ParseDouble(value, () => section.Path); + return ParseDouble(value, section.Path); } } @@ -146,7 +146,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -154,11 +154,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static float ParseFloat(string value, Func getPath) + public static float ParseFloat(string value, string? path) { try { @@ -166,11 +166,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(float)}'.", exception); } } - public static double ParseDouble(string value, Func getPath) + public static double ParseDouble(string value, string? path) { try { @@ -178,7 +178,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(double)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T.generated.txt index 8eecd3ba72a1e..470d6857874f5 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T.generated.txt @@ -72,7 +72,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -85,7 +85,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp1.Add(ParseInt(value, () => section.Path)); + temp1.Add(ParseInt(value, section.Path)); } } @@ -116,7 +116,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value3) { - instance.MyInt = ParseInt(value3, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value3, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -207,7 +207,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -215,7 +215,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T_BinderOptions.generated.txt index ec88c39f20a2d..3f0d165c40c14 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_T_BinderOptions.generated.txt @@ -72,7 +72,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -85,7 +85,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp1.Add(ParseInt(value, () => section.Path)); + temp1.Add(ParseInt(value, section.Path)); } } @@ -116,7 +116,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value3) { - instance.MyInt = ParseInt(value3, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value3, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -207,7 +207,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -215,7 +215,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf.generated.txt index 46c24547478ab..5b5050214620b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf.generated.txt @@ -72,7 +72,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -139,7 +139,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -147,7 +147,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt index f37307065a78e..039e2eecef843 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt @@ -72,7 +72,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -139,7 +139,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -147,7 +147,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/DefaultConstructorParameters.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/DefaultConstructorParameters.generated.txt index e76b1450e4720..3780c1a56ce14 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/DefaultConstructorParameters.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/DefaultConstructorParameters.generated.txt @@ -78,73 +78,73 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration int age = (int)(42); if (configuration["Age"] is string value2) { - age = ParseInt(value2, () => configuration.GetSection("Age").Path); + age = ParseInt(value2, configuration.GetSection("Age").Path); } float f = 42F; if (configuration["F"] is string value3) { - f = ParseFloat(value3, () => configuration.GetSection("F").Path); + f = ParseFloat(value3, configuration.GetSection("F").Path); } double d = 3.1415899999999999D; if (configuration["D"] is string value4) { - d = ParseDouble(value4, () => configuration.GetSection("D").Path); + d = ParseDouble(value4, configuration.GetSection("D").Path); } decimal m = 3.1415926535897932384626433M; if (configuration["M"] is string value5) { - m = ParseDecimal(value5, () => configuration.GetSection("M").Path); + m = ParseDecimal(value5, configuration.GetSection("M").Path); } global::System.StringComparison sc = (global::System.StringComparison)(4); if (configuration["SC"] is string value6) { - sc = ParseEnum(value6, () => configuration.GetSection("SC").Path); + sc = ParseEnum(value6, configuration.GetSection("SC").Path); } char c = 'q'; if (configuration["C"] is string value7) { - c = ParseChar(value7, () => configuration.GetSection("C").Path); + c = ParseChar(value7, configuration.GetSection("C").Path); } int? nage = (int?)(42); if (configuration["NAge"] is string value8) { - nage = ParseInt(value8, () => configuration.GetSection("NAge").Path); + nage = ParseInt(value8, configuration.GetSection("NAge").Path); } float? nf = 42F; if (configuration["NF"] is string value9) { - nf = ParseFloat(value9, () => configuration.GetSection("NF").Path); + nf = ParseFloat(value9, configuration.GetSection("NF").Path); } double? nd = 3.1415899999999999D; if (configuration["ND"] is string value10) { - nd = ParseDouble(value10, () => configuration.GetSection("ND").Path); + nd = ParseDouble(value10, configuration.GetSection("ND").Path); } decimal? nm = 3.1415926535897932384626433M; if (configuration["NM"] is string value11) { - nm = ParseDecimal(value11, () => configuration.GetSection("NM").Path); + nm = ParseDecimal(value11, configuration.GetSection("NM").Path); } global::System.StringComparison? nsc = (global::System.StringComparison?)(4); if (configuration["NSC"] is string value12) { - nsc = ParseEnum(value12, () => configuration.GetSection("NSC").Path); + nsc = ParseEnum(value12, configuration.GetSection("NSC").Path); } char? nc = 'q'; if (configuration["NC"] is string value13) { - nc = ParseChar(value13, () => configuration.GetSection("NC").Path); + nc = ParseChar(value13, configuration.GetSection("NC").Path); } return new global::Program.ClassWhereParametersHaveDefaultValue(name, address, age, f, d, m, sc, c, nage, nf, nd, nm, nsc, nc); @@ -173,7 +173,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } } - public static T ParseEnum(string value, Func getPath) where T : struct + public static T ParseEnum(string value, string? path) where T : struct { try { @@ -181,11 +181,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(T)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(T)}'.", exception); } } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -193,11 +193,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static float ParseFloat(string value, Func getPath) + public static float ParseFloat(string value, string? path) { try { @@ -205,11 +205,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(float)}'.", exception); } } - public static double ParseDouble(string value, Func getPath) + public static double ParseDouble(string value, string? path) { try { @@ -217,11 +217,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(double)}'.", exception); } } - public static decimal ParseDecimal(string value, Func getPath) + public static decimal ParseDecimal(string value, string? path) { try { @@ -229,11 +229,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(decimal)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(decimal)}'.", exception); } } - public static char ParseChar(string value, Func getPath) + public static char ParseChar(string value, string? path) { try { @@ -241,7 +241,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(char)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(char)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/BindConfiguration.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/BindConfiguration.generated.txt index e5b2254220fcf..87515b8b4b326 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/BindConfiguration.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/BindConfiguration.generated.txt @@ -103,7 +103,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -119,7 +119,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value2) { - instance.MyInt = ParseInt(value2, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value2, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -194,7 +194,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -202,7 +202,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T.generated.txt index 1907c52599323..8b31876d5bac8 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T.generated.txt @@ -109,7 +109,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -125,7 +125,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value2) { - instance.MyInt = ParseInt(value2, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value2, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -200,7 +200,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -208,7 +208,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T_BinderOptions.generated.txt index b3eb6354b5dbf..e58ef0662ee21 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Bind_T_BinderOptions.generated.txt @@ -103,7 +103,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -119,7 +119,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value2) { - instance.MyInt = ParseInt(value2, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value2, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -194,7 +194,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -202,7 +202,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Primitives.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Primitives.generated.txt index 90c6a72aa4e55..39cfc67e44f95 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Primitives.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Primitives.generated.txt @@ -62,7 +62,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop0"] is string value0) { - instance.Prop0 = ParseBool(value0, () => configuration.GetSection("Prop0").Path); + instance.Prop0 = ParseBool(value0, configuration.GetSection("Prop0").Path); } else if (defaultValueIfNotFound) { @@ -71,7 +71,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop1"] is string value1) { - instance.Prop1 = ParseByte(value1, () => configuration.GetSection("Prop1").Path); + instance.Prop1 = ParseByte(value1, configuration.GetSection("Prop1").Path); } else if (defaultValueIfNotFound) { @@ -80,7 +80,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop2"] is string value2) { - instance.Prop2 = ParseSbyte(value2, () => configuration.GetSection("Prop2").Path); + instance.Prop2 = ParseSbyte(value2, configuration.GetSection("Prop2").Path); } else if (defaultValueIfNotFound) { @@ -89,7 +89,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop3"] is string value3) { - instance.Prop3 = ParseChar(value3, () => configuration.GetSection("Prop3").Path); + instance.Prop3 = ParseChar(value3, configuration.GetSection("Prop3").Path); } else if (defaultValueIfNotFound) { @@ -98,7 +98,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop4"] is string value4) { - instance.Prop4 = ParseDouble(value4, () => configuration.GetSection("Prop4").Path); + instance.Prop4 = ParseDouble(value4, configuration.GetSection("Prop4").Path); } else if (defaultValueIfNotFound) { @@ -112,7 +112,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop6"] is string value6) { - instance.Prop6 = ParseInt(value6, () => configuration.GetSection("Prop6").Path); + instance.Prop6 = ParseInt(value6, configuration.GetSection("Prop6").Path); } else if (defaultValueIfNotFound) { @@ -121,7 +121,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop8"] is string value7) { - instance.Prop8 = ParseShort(value7, () => configuration.GetSection("Prop8").Path); + instance.Prop8 = ParseShort(value7, configuration.GetSection("Prop8").Path); } else if (defaultValueIfNotFound) { @@ -130,7 +130,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop9"] is string value8) { - instance.Prop9 = ParseLong(value8, () => configuration.GetSection("Prop9").Path); + instance.Prop9 = ParseLong(value8, configuration.GetSection("Prop9").Path); } else if (defaultValueIfNotFound) { @@ -139,7 +139,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop10"] is string value9) { - instance.Prop10 = ParseFloat(value9, () => configuration.GetSection("Prop10").Path); + instance.Prop10 = ParseFloat(value9, configuration.GetSection("Prop10").Path); } else if (defaultValueIfNotFound) { @@ -148,7 +148,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop13"] is string value10) { - instance.Prop13 = ParseUshort(value10, () => configuration.GetSection("Prop13").Path); + instance.Prop13 = ParseUshort(value10, configuration.GetSection("Prop13").Path); } else if (defaultValueIfNotFound) { @@ -157,7 +157,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop14"] is string value11) { - instance.Prop14 = ParseUint(value11, () => configuration.GetSection("Prop14").Path); + instance.Prop14 = ParseUint(value11, configuration.GetSection("Prop14").Path); } else if (defaultValueIfNotFound) { @@ -166,7 +166,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop15"] is string value12) { - instance.Prop15 = ParseUlong(value12, () => configuration.GetSection("Prop15").Path); + instance.Prop15 = ParseUlong(value12, configuration.GetSection("Prop15").Path); } else if (defaultValueIfNotFound) { @@ -180,12 +180,12 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop17"] is string value14) { - instance.Prop17 = ParseSystemGlobalizationCultureInfo(value14, () => configuration.GetSection("Prop17").Path); + instance.Prop17 = ParseSystemGlobalizationCultureInfo(value14, configuration.GetSection("Prop17").Path); } if (configuration["Prop19"] is string value15) { - instance.Prop19 = ParseSystemDateTime(value15, () => configuration.GetSection("Prop19").Path); + instance.Prop19 = ParseSystemDateTime(value15, configuration.GetSection("Prop19").Path); } else if (defaultValueIfNotFound) { @@ -194,7 +194,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop20"] is string value16) { - instance.Prop20 = ParseSystemDateTimeOffset(value16, () => configuration.GetSection("Prop20").Path); + instance.Prop20 = ParseSystemDateTimeOffset(value16, configuration.GetSection("Prop20").Path); } else if (defaultValueIfNotFound) { @@ -203,7 +203,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop21"] is string value17) { - instance.Prop21 = ParseDecimal(value17, () => configuration.GetSection("Prop21").Path); + instance.Prop21 = ParseDecimal(value17, configuration.GetSection("Prop21").Path); } else if (defaultValueIfNotFound) { @@ -212,7 +212,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop23"] is string value18) { - instance.Prop23 = ParseSystemTimeSpan(value18, () => configuration.GetSection("Prop23").Path); + instance.Prop23 = ParseSystemTimeSpan(value18, configuration.GetSection("Prop23").Path); } else if (defaultValueIfNotFound) { @@ -221,7 +221,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop24"] is string value19) { - instance.Prop24 = ParseSystemGuid(value19, () => configuration.GetSection("Prop24").Path); + instance.Prop24 = ParseSystemGuid(value19, configuration.GetSection("Prop24").Path); } else if (defaultValueIfNotFound) { @@ -230,17 +230,17 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop25"] is string value20) { - instance.Prop25 = ParseSystemUri(value20, () => configuration.GetSection("Prop25").Path); + instance.Prop25 = ParseSystemUri(value20, configuration.GetSection("Prop25").Path); } if (configuration["Prop26"] is string value21) { - instance.Prop26 = ParseSystemVersion(value21, () => configuration.GetSection("Prop26").Path); + instance.Prop26 = ParseSystemVersion(value21, configuration.GetSection("Prop26").Path); } if (configuration["Prop27"] is string value22) { - instance.Prop27 = ParseEnum(value22, () => configuration.GetSection("Prop27").Path); + instance.Prop27 = ParseEnum(value22, configuration.GetSection("Prop27").Path); } else if (defaultValueIfNotFound) { @@ -249,12 +249,12 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop28"] is string value23) { - instance.Prop28 = ParseByteArray(value23, () => configuration.GetSection("Prop28").Path); + instance.Prop28 = ParseByteArray(value23, configuration.GetSection("Prop28").Path); } if (configuration["Prop29"] is string value24) { - instance.Prop29 = ParseInt(value24, () => configuration.GetSection("Prop29").Path); + instance.Prop29 = ParseInt(value24, configuration.GetSection("Prop29").Path); } else if (defaultValueIfNotFound) { @@ -263,7 +263,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop30"] is string value25) { - instance.Prop30 = ParseSystemDateTime(value25, () => configuration.GetSection("Prop30").Path); + instance.Prop30 = ParseSystemDateTime(value25, configuration.GetSection("Prop30").Path); } else if (defaultValueIfNotFound) { @@ -294,7 +294,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } } - public static T ParseEnum(string value, Func getPath) where T : struct + public static T ParseEnum(string value, string? path) where T : struct { try { @@ -302,11 +302,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(T)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(T)}'.", exception); } } - public static bool ParseBool(string value, Func getPath) + public static bool ParseBool(string value, string? path) { try { @@ -314,11 +314,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(bool)}'.", exception); } } - public static byte ParseByte(string value, Func getPath) + public static byte ParseByte(string value, string? path) { try { @@ -326,11 +326,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(byte)}'.", exception); } } - public static sbyte ParseSbyte(string value, Func getPath) + public static sbyte ParseSbyte(string value, string? path) { try { @@ -338,11 +338,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(sbyte)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(sbyte)}'.", exception); } } - public static char ParseChar(string value, Func getPath) + public static char ParseChar(string value, string? path) { try { @@ -350,11 +350,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(char)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(char)}'.", exception); } } - public static double ParseDouble(string value, Func getPath) + public static double ParseDouble(string value, string? path) { try { @@ -362,11 +362,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(double)}'.", exception); } } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -374,11 +374,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static short ParseShort(string value, Func getPath) + public static short ParseShort(string value, string? path) { try { @@ -386,11 +386,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(short)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(short)}'.", exception); } } - public static long ParseLong(string value, Func getPath) + public static long ParseLong(string value, string? path) { try { @@ -398,11 +398,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(long)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(long)}'.", exception); } } - public static float ParseFloat(string value, Func getPath) + public static float ParseFloat(string value, string? path) { try { @@ -410,11 +410,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(float)}'.", exception); } } - public static ushort ParseUshort(string value, Func getPath) + public static ushort ParseUshort(string value, string? path) { try { @@ -422,11 +422,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ushort)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(ushort)}'.", exception); } } - public static uint ParseUint(string value, Func getPath) + public static uint ParseUint(string value, string? path) { try { @@ -434,11 +434,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(uint)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(uint)}'.", exception); } } - public static ulong ParseUlong(string value, Func getPath) + public static ulong ParseUlong(string value, string? path) { try { @@ -446,11 +446,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ulong)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(ulong)}'.", exception); } } - public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func getPath) + public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, string? path) { try { @@ -458,11 +458,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); } } - public static global::System.DateTime ParseSystemDateTime(string value, Func getPath) + public static global::System.DateTime ParseSystemDateTime(string value, string? path) { try { @@ -470,11 +470,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateTime)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.DateTime)}'.", exception); } } - public static global::System.DateTimeOffset ParseSystemDateTimeOffset(string value, Func getPath) + public static global::System.DateTimeOffset ParseSystemDateTimeOffset(string value, string? path) { try { @@ -482,11 +482,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateTimeOffset)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.DateTimeOffset)}'.", exception); } } - public static decimal ParseDecimal(string value, Func getPath) + public static decimal ParseDecimal(string value, string? path) { try { @@ -494,11 +494,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(decimal)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(decimal)}'.", exception); } } - public static global::System.TimeSpan ParseSystemTimeSpan(string value, Func getPath) + public static global::System.TimeSpan ParseSystemTimeSpan(string value, string? path) { try { @@ -506,11 +506,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.TimeSpan)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.TimeSpan)}'.", exception); } } - public static global::System.Guid ParseSystemGuid(string value, Func getPath) + public static global::System.Guid ParseSystemGuid(string value, string? path) { try { @@ -518,11 +518,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Guid)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Guid)}'.", exception); } } - public static global::System.Uri ParseSystemUri(string value, Func getPath) + public static global::System.Uri ParseSystemUri(string value, string? path) { try { @@ -530,11 +530,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Uri)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Uri)}'.", exception); } } - public static global::System.Version ParseSystemVersion(string value, Func getPath) + public static global::System.Version ParseSystemVersion(string value, string? path) { try { @@ -542,11 +542,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Version)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Version)}'.", exception); } } - public static byte[] ParseByteArray(string value, Func getPath) + public static byte[] ParseByteArray(string value, string? path) { try { @@ -554,7 +554,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte[])}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(byte[])}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T.generated.txt index a3f236c191046..9da38162f69c6 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T.generated.txt @@ -97,7 +97,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -108,7 +108,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -152,7 +152,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -243,7 +243,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -251,7 +251,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_BinderOptions.generated.txt index b7207282c9490..c61cb79650c6c 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_BinderOptions.generated.txt @@ -97,7 +97,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -108,7 +108,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -152,7 +152,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -243,7 +243,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -251,7 +251,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name.generated.txt index 3238545870fac..72e2503fd5b27 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name.generated.txt @@ -97,7 +97,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -108,7 +108,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -152,7 +152,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -243,7 +243,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -251,7 +251,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name_BinderOptions.generated.txt index 634a091f2755e..e09478cf4aed2 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Configure_T_name_BinderOptions.generated.txt @@ -91,7 +91,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -102,7 +102,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -146,7 +146,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -237,7 +237,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -245,7 +245,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/UnsupportedTypes.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/UnsupportedTypes.generated.txt index e2a440440c540..d9d9ddc9e7fd8 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/UnsupportedTypes.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/UnsupportedTypes.generated.txt @@ -137,7 +137,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Age"] is string value3) { - instance.Age = ParseInt(value3, () => configuration.GetSection("Age").Path); + instance.Age = ParseInt(value3, configuration.GetSection("Age").Path); } else if (defaultValueIfNotFound) { @@ -174,7 +174,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration int x = (int)(10); if (configuration["x"] is string value13) { - x = ParseInt(value13, () => configuration.GetSection("x").Path); + x = ParseInt(value13, configuration.GetSection("x").Path); } return new global::Record(x) @@ -242,7 +242,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -250,7 +250,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Collections.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Collections.generated.txt index b489907db9005..b8d24de4a64e7 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Collections.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Collections.generated.txt @@ -70,7 +70,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance[section.Key] = ParseInt(value, () => section.Path); + instance[section.Key] = ParseInt(value, section.Path); } } } @@ -97,7 +97,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp.Add(ParseInt(value, () => section.Path)); + temp.Add(ParseInt(value, section.Path)); } } } @@ -113,7 +113,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp[section.Key] = ParseInt(value, () => section.Path); + temp[section.Key] = ParseInt(value, section.Path); } } } @@ -214,7 +214,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -222,7 +222,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind.generated.txt index da0c7375e13f6..15bfede964efd 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind.generated.txt @@ -89,7 +89,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -128,7 +128,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -210,7 +210,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -218,7 +218,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance.generated.txt index 336d1b5a9f4ca..e3baa0a479610 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance.generated.txt @@ -59,7 +59,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -98,7 +98,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -162,7 +162,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -170,7 +170,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt index 80c908cedbee2..975b2bf790001 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Instance_BinderOptions.generated.txt @@ -59,7 +59,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -98,7 +98,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -180,7 +180,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -188,7 +188,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Key_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Key_Instance.generated.txt index 592e8f14ae410..f8a85a2c6ea1a 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Key_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Bind_Key_Instance.generated.txt @@ -59,7 +59,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -98,7 +98,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -162,7 +162,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -170,7 +170,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get.generated.txt index 0c631bfc10e6a..210cc441463f9 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get.generated.txt @@ -88,7 +88,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -101,7 +101,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp2.Add(ParseInt(value, () => section.Path)); + temp2.Add(ParseInt(value, section.Path)); } } @@ -132,7 +132,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -170,7 +170,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value14) { - instance.MyInt = ParseInt(value14, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value14, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -237,7 +237,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -245,7 +245,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue.generated.txt index 72edaaf8c6fba..1b4db77eaa312 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue.generated.txt @@ -66,25 +66,25 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(int)) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } else if (type == typeof(bool?)) { - return ParseBool(value, () => section.Path); + return ParseBool(value, section.Path); } else if (type == typeof(byte[])) { - return ParseByteArray(value, () => section.Path); + return ParseByteArray(value, section.Path); } else if (type == typeof(global::System.Globalization.CultureInfo)) { - return ParseSystemGlobalizationCultureInfo(value, () => section.Path); + return ParseSystemGlobalizationCultureInfo(value, section.Path); } return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -92,11 +92,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static bool ParseBool(string value, Func getPath) + public static bool ParseBool(string value, string? path) { try { @@ -104,11 +104,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(bool)}'.", exception); } } - public static byte[] ParseByteArray(string value, Func getPath) + public static byte[] ParseByteArray(string value, string? path) { try { @@ -116,11 +116,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte[])}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(byte[])}'.", exception); } } - public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func getPath) + public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, string? path) { try { @@ -128,7 +128,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key.generated.txt index 678fa163a57c8..f941602574bfc 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key.generated.txt @@ -52,13 +52,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(int)) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -66,7 +66,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt index c383398924de6..b4e732218e364 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_T_Key_DefaultValue.generated.txt @@ -53,13 +53,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(int)) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } return null; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -67,7 +67,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt index 706dec382c863..071e80f21f7a1 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key.generated.txt @@ -52,13 +52,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(bool?)) { - return ParseBool(value, () => section.Path); + return ParseBool(value, section.Path); } return null; } - public static bool ParseBool(string value, Func getPath) + public static bool ParseBool(string value, string? path) { try { @@ -66,7 +66,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(bool)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt index 8371cd0b05ca1..a8a4333c82fcf 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/GetValue_TypeOf_Key_DefaultValue.generated.txt @@ -53,13 +53,13 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (type == typeof(global::System.Globalization.CultureInfo)) { - return ParseSystemGlobalizationCultureInfo(value, () => section.Path); + return ParseSystemGlobalizationCultureInfo(value, section.Path); } return null; } - public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func getPath) + public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, string? path) { try { @@ -67,7 +67,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_PrimitivesOnly.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_PrimitivesOnly.generated.txt index 4934212d5836a..b47e3b04fe558 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_PrimitivesOnly.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_PrimitivesOnly.generated.txt @@ -70,7 +70,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } if (section.Value is string value) { - return ParseInt(value, () => section.Path); + return ParseInt(value, section.Path); } } else if (type == typeof(string)) @@ -89,7 +89,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } if (section.Value is string value) { - return ParseFloat(value, () => section.Path); + return ParseFloat(value, section.Path); } } else if (type == typeof(double)) @@ -100,7 +100,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } if (section.Value is string value) { - return ParseDouble(value, () => section.Path); + return ParseDouble(value, section.Path); } } @@ -143,7 +143,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -151,11 +151,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static float ParseFloat(string value, Func getPath) + public static float ParseFloat(string value, string? path) { try { @@ -163,11 +163,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(float)}'.", exception); } } - public static double ParseDouble(string value, Func getPath) + public static double ParseDouble(string value, string? path) { try { @@ -175,7 +175,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(double)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T.generated.txt index 93766ec1d4050..7e8a129fb206f 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T.generated.txt @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -82,7 +82,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp1.Add(ParseInt(value, () => section.Path)); + temp1.Add(ParseInt(value, section.Path)); } } @@ -113,7 +113,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value3) { - instance.MyInt = ParseInt(value3, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value3, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -204,7 +204,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -212,7 +212,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T_BinderOptions.generated.txt index caae5dfc5a836..7e265b8924196 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_T_BinderOptions.generated.txt @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -82,7 +82,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - temp1.Add(ParseInt(value, () => section.Path)); + temp1.Add(ParseInt(value, section.Path)); } } @@ -113,7 +113,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value3) { - instance.MyInt = ParseInt(value3, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value3, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -204,7 +204,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -212,7 +212,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf.generated.txt index 9c28e846781de..fbfde08c46327 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf.generated.txt @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -136,7 +136,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -144,7 +144,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt index c2b86bd863e49..8e4a799bcdd0b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Get_TypeOf_BinderOptions.generated.txt @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -136,7 +136,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -144,7 +144,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/DefaultConstructorParameters.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/DefaultConstructorParameters.generated.txt index 052829b264155..8b1c55c52e853 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/DefaultConstructorParameters.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/DefaultConstructorParameters.generated.txt @@ -75,73 +75,73 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration int age = (int)(42); if (configuration["Age"] is string value2) { - age = ParseInt(value2, () => configuration.GetSection("Age").Path); + age = ParseInt(value2, configuration.GetSection("Age").Path); } float f = 42F; if (configuration["F"] is string value3) { - f = ParseFloat(value3, () => configuration.GetSection("F").Path); + f = ParseFloat(value3, configuration.GetSection("F").Path); } double d = 3.1415899999999999D; if (configuration["D"] is string value4) { - d = ParseDouble(value4, () => configuration.GetSection("D").Path); + d = ParseDouble(value4, configuration.GetSection("D").Path); } decimal m = 3.1415926535897932384626433M; if (configuration["M"] is string value5) { - m = ParseDecimal(value5, () => configuration.GetSection("M").Path); + m = ParseDecimal(value5, configuration.GetSection("M").Path); } global::System.StringComparison sc = (global::System.StringComparison)(4); if (configuration["SC"] is string value6) { - sc = ParseEnum(value6, () => configuration.GetSection("SC").Path); + sc = ParseEnum(value6, configuration.GetSection("SC").Path); } char c = 'q'; if (configuration["C"] is string value7) { - c = ParseChar(value7, () => configuration.GetSection("C").Path); + c = ParseChar(value7, configuration.GetSection("C").Path); } int? nage = (int?)(42); if (configuration["NAge"] is string value8) { - nage = ParseInt(value8, () => configuration.GetSection("NAge").Path); + nage = ParseInt(value8, configuration.GetSection("NAge").Path); } float? nf = 42F; if (configuration["NF"] is string value9) { - nf = ParseFloat(value9, () => configuration.GetSection("NF").Path); + nf = ParseFloat(value9, configuration.GetSection("NF").Path); } double? nd = 3.1415899999999999D; if (configuration["ND"] is string value10) { - nd = ParseDouble(value10, () => configuration.GetSection("ND").Path); + nd = ParseDouble(value10, configuration.GetSection("ND").Path); } decimal? nm = 3.1415926535897932384626433M; if (configuration["NM"] is string value11) { - nm = ParseDecimal(value11, () => configuration.GetSection("NM").Path); + nm = ParseDecimal(value11, configuration.GetSection("NM").Path); } global::System.StringComparison? nsc = (global::System.StringComparison?)(4); if (configuration["NSC"] is string value12) { - nsc = ParseEnum(value12, () => configuration.GetSection("NSC").Path); + nsc = ParseEnum(value12, configuration.GetSection("NSC").Path); } char? nc = 'q'; if (configuration["NC"] is string value13) { - nc = ParseChar(value13, () => configuration.GetSection("NC").Path); + nc = ParseChar(value13, configuration.GetSection("NC").Path); } return new global::Program.ClassWhereParametersHaveDefaultValue(name, address, age, f, d, m, sc, c, nage, nf, nd, nm, nsc, nc); @@ -170,7 +170,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } } - public static T ParseEnum(string value, Func getPath) where T : struct + public static T ParseEnum(string value, string? path) where T : struct { try { @@ -178,11 +178,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(T)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(T)}'.", exception); } } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -190,11 +190,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static float ParseFloat(string value, Func getPath) + public static float ParseFloat(string value, string? path) { try { @@ -202,11 +202,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(float)}'.", exception); } } - public static double ParseDouble(string value, Func getPath) + public static double ParseDouble(string value, string? path) { try { @@ -214,11 +214,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(double)}'.", exception); } } - public static decimal ParseDecimal(string value, Func getPath) + public static decimal ParseDecimal(string value, string? path) { try { @@ -226,11 +226,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(decimal)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(decimal)}'.", exception); } } - public static char ParseChar(string value, Func getPath) + public static char ParseChar(string value, string? path) { try { @@ -238,7 +238,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(char)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(char)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/BindConfiguration.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/BindConfiguration.generated.txt index d09432aa25833..0ac91850d67a6 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/BindConfiguration.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/BindConfiguration.generated.txt @@ -94,7 +94,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -110,7 +110,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value2) { - instance.MyInt = ParseInt(value2, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value2, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -185,7 +185,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -193,7 +193,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T.generated.txt index 1d116049774fe..bd896297fec6b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T.generated.txt @@ -100,7 +100,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -116,7 +116,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value2) { - instance.MyInt = ParseInt(value2, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value2, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -191,7 +191,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -199,7 +199,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T_BinderOptions.generated.txt index 2a1abf7f17d36..56682ad884a6a 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Bind_T_BinderOptions.generated.txt @@ -94,7 +94,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -110,7 +110,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value2) { - instance.MyInt = ParseInt(value2, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value2, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -185,7 +185,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -193,7 +193,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Primitives.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Primitives.generated.txt index fdbe79002b2d3..31cd91c8cfd0b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Primitives.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Primitives.generated.txt @@ -59,7 +59,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop0"] is string value0) { - instance.Prop0 = ParseBool(value0, () => configuration.GetSection("Prop0").Path); + instance.Prop0 = ParseBool(value0, configuration.GetSection("Prop0").Path); } else if (defaultValueIfNotFound) { @@ -68,7 +68,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop1"] is string value1) { - instance.Prop1 = ParseByte(value1, () => configuration.GetSection("Prop1").Path); + instance.Prop1 = ParseByte(value1, configuration.GetSection("Prop1").Path); } else if (defaultValueIfNotFound) { @@ -77,7 +77,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop2"] is string value2) { - instance.Prop2 = ParseSbyte(value2, () => configuration.GetSection("Prop2").Path); + instance.Prop2 = ParseSbyte(value2, configuration.GetSection("Prop2").Path); } else if (defaultValueIfNotFound) { @@ -86,7 +86,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop3"] is string value3) { - instance.Prop3 = ParseChar(value3, () => configuration.GetSection("Prop3").Path); + instance.Prop3 = ParseChar(value3, configuration.GetSection("Prop3").Path); } else if (defaultValueIfNotFound) { @@ -95,7 +95,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop4"] is string value4) { - instance.Prop4 = ParseDouble(value4, () => configuration.GetSection("Prop4").Path); + instance.Prop4 = ParseDouble(value4, configuration.GetSection("Prop4").Path); } else if (defaultValueIfNotFound) { @@ -109,7 +109,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop6"] is string value6) { - instance.Prop6 = ParseInt(value6, () => configuration.GetSection("Prop6").Path); + instance.Prop6 = ParseInt(value6, configuration.GetSection("Prop6").Path); } else if (defaultValueIfNotFound) { @@ -118,7 +118,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop8"] is string value7) { - instance.Prop8 = ParseShort(value7, () => configuration.GetSection("Prop8").Path); + instance.Prop8 = ParseShort(value7, configuration.GetSection("Prop8").Path); } else if (defaultValueIfNotFound) { @@ -127,7 +127,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop9"] is string value8) { - instance.Prop9 = ParseLong(value8, () => configuration.GetSection("Prop9").Path); + instance.Prop9 = ParseLong(value8, configuration.GetSection("Prop9").Path); } else if (defaultValueIfNotFound) { @@ -136,7 +136,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop10"] is string value9) { - instance.Prop10 = ParseFloat(value9, () => configuration.GetSection("Prop10").Path); + instance.Prop10 = ParseFloat(value9, configuration.GetSection("Prop10").Path); } else if (defaultValueIfNotFound) { @@ -145,7 +145,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop13"] is string value10) { - instance.Prop13 = ParseUshort(value10, () => configuration.GetSection("Prop13").Path); + instance.Prop13 = ParseUshort(value10, configuration.GetSection("Prop13").Path); } else if (defaultValueIfNotFound) { @@ -154,7 +154,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop14"] is string value11) { - instance.Prop14 = ParseUint(value11, () => configuration.GetSection("Prop14").Path); + instance.Prop14 = ParseUint(value11, configuration.GetSection("Prop14").Path); } else if (defaultValueIfNotFound) { @@ -163,7 +163,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop15"] is string value12) { - instance.Prop15 = ParseUlong(value12, () => configuration.GetSection("Prop15").Path); + instance.Prop15 = ParseUlong(value12, configuration.GetSection("Prop15").Path); } else if (defaultValueIfNotFound) { @@ -177,12 +177,12 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop17"] is string value14) { - instance.Prop17 = ParseSystemGlobalizationCultureInfo(value14, () => configuration.GetSection("Prop17").Path); + instance.Prop17 = ParseSystemGlobalizationCultureInfo(value14, configuration.GetSection("Prop17").Path); } if (configuration["Prop19"] is string value15) { - instance.Prop19 = ParseSystemDateTime(value15, () => configuration.GetSection("Prop19").Path); + instance.Prop19 = ParseSystemDateTime(value15, configuration.GetSection("Prop19").Path); } else if (defaultValueIfNotFound) { @@ -191,7 +191,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop20"] is string value16) { - instance.Prop20 = ParseSystemDateTimeOffset(value16, () => configuration.GetSection("Prop20").Path); + instance.Prop20 = ParseSystemDateTimeOffset(value16, configuration.GetSection("Prop20").Path); } else if (defaultValueIfNotFound) { @@ -200,7 +200,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop21"] is string value17) { - instance.Prop21 = ParseDecimal(value17, () => configuration.GetSection("Prop21").Path); + instance.Prop21 = ParseDecimal(value17, configuration.GetSection("Prop21").Path); } else if (defaultValueIfNotFound) { @@ -209,7 +209,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop23"] is string value18) { - instance.Prop23 = ParseSystemTimeSpan(value18, () => configuration.GetSection("Prop23").Path); + instance.Prop23 = ParseSystemTimeSpan(value18, configuration.GetSection("Prop23").Path); } else if (defaultValueIfNotFound) { @@ -218,7 +218,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop24"] is string value19) { - instance.Prop24 = ParseSystemGuid(value19, () => configuration.GetSection("Prop24").Path); + instance.Prop24 = ParseSystemGuid(value19, configuration.GetSection("Prop24").Path); } else if (defaultValueIfNotFound) { @@ -227,17 +227,17 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop25"] is string value20) { - instance.Prop25 = ParseSystemUri(value20, () => configuration.GetSection("Prop25").Path); + instance.Prop25 = ParseSystemUri(value20, configuration.GetSection("Prop25").Path); } if (configuration["Prop26"] is string value21) { - instance.Prop26 = ParseSystemVersion(value21, () => configuration.GetSection("Prop26").Path); + instance.Prop26 = ParseSystemVersion(value21, configuration.GetSection("Prop26").Path); } if (configuration["Prop27"] is string value22) { - instance.Prop27 = ParseEnum(value22, () => configuration.GetSection("Prop27").Path); + instance.Prop27 = ParseEnum(value22, configuration.GetSection("Prop27").Path); } else if (defaultValueIfNotFound) { @@ -246,7 +246,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop7"] is string value23) { - instance.Prop7 = ParseSystemInt128(value23, () => configuration.GetSection("Prop7").Path); + instance.Prop7 = ParseSystemInt128(value23, configuration.GetSection("Prop7").Path); } else if (defaultValueIfNotFound) { @@ -255,7 +255,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop11"] is string value24) { - instance.Prop11 = ParseSystemHalf(value24, () => configuration.GetSection("Prop11").Path); + instance.Prop11 = ParseSystemHalf(value24, configuration.GetSection("Prop11").Path); } else if (defaultValueIfNotFound) { @@ -264,7 +264,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop12"] is string value25) { - instance.Prop12 = ParseSystemUInt128(value25, () => configuration.GetSection("Prop12").Path); + instance.Prop12 = ParseSystemUInt128(value25, configuration.GetSection("Prop12").Path); } else if (defaultValueIfNotFound) { @@ -273,7 +273,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop18"] is string value26) { - instance.Prop18 = ParseSystemDateOnly(value26, () => configuration.GetSection("Prop18").Path); + instance.Prop18 = ParseSystemDateOnly(value26, configuration.GetSection("Prop18").Path); } else if (defaultValueIfNotFound) { @@ -282,7 +282,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop22"] is string value27) { - instance.Prop22 = ParseSystemTimeOnly(value27, () => configuration.GetSection("Prop22").Path); + instance.Prop22 = ParseSystemTimeOnly(value27, configuration.GetSection("Prop22").Path); } else if (defaultValueIfNotFound) { @@ -291,12 +291,12 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop28"] is string value28) { - instance.Prop28 = ParseByteArray(value28, () => configuration.GetSection("Prop28").Path); + instance.Prop28 = ParseByteArray(value28, configuration.GetSection("Prop28").Path); } if (configuration["Prop29"] is string value29) { - instance.Prop29 = ParseInt(value29, () => configuration.GetSection("Prop29").Path); + instance.Prop29 = ParseInt(value29, configuration.GetSection("Prop29").Path); } else if (defaultValueIfNotFound) { @@ -305,7 +305,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Prop30"] is string value30) { - instance.Prop30 = ParseSystemDateTime(value30, () => configuration.GetSection("Prop30").Path); + instance.Prop30 = ParseSystemDateTime(value30, configuration.GetSection("Prop30").Path); } else if (defaultValueIfNotFound) { @@ -336,7 +336,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } } - public static T ParseEnum(string value, Func getPath) where T : struct + public static T ParseEnum(string value, string? path) where T : struct { try { @@ -344,11 +344,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(T)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(T)}'.", exception); } } - public static bool ParseBool(string value, Func getPath) + public static bool ParseBool(string value, string? path) { try { @@ -356,11 +356,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(bool)}'.", exception); } } - public static byte ParseByte(string value, Func getPath) + public static byte ParseByte(string value, string? path) { try { @@ -368,11 +368,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(byte)}'.", exception); } } - public static sbyte ParseSbyte(string value, Func getPath) + public static sbyte ParseSbyte(string value, string? path) { try { @@ -380,11 +380,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(sbyte)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(sbyte)}'.", exception); } } - public static char ParseChar(string value, Func getPath) + public static char ParseChar(string value, string? path) { try { @@ -392,11 +392,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(char)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(char)}'.", exception); } } - public static double ParseDouble(string value, Func getPath) + public static double ParseDouble(string value, string? path) { try { @@ -404,11 +404,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(double)}'.", exception); } } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -416,11 +416,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } - public static short ParseShort(string value, Func getPath) + public static short ParseShort(string value, string? path) { try { @@ -428,11 +428,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(short)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(short)}'.", exception); } } - public static long ParseLong(string value, Func getPath) + public static long ParseLong(string value, string? path) { try { @@ -440,11 +440,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(long)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(long)}'.", exception); } } - public static float ParseFloat(string value, Func getPath) + public static float ParseFloat(string value, string? path) { try { @@ -452,11 +452,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(float)}'.", exception); } } - public static ushort ParseUshort(string value, Func getPath) + public static ushort ParseUshort(string value, string? path) { try { @@ -464,11 +464,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ushort)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(ushort)}'.", exception); } } - public static uint ParseUint(string value, Func getPath) + public static uint ParseUint(string value, string? path) { try { @@ -476,11 +476,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(uint)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(uint)}'.", exception); } } - public static ulong ParseUlong(string value, Func getPath) + public static ulong ParseUlong(string value, string? path) { try { @@ -488,11 +488,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ulong)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(ulong)}'.", exception); } } - public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func getPath) + public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, string? path) { try { @@ -500,11 +500,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception); } } - public static global::System.DateTime ParseSystemDateTime(string value, Func getPath) + public static global::System.DateTime ParseSystemDateTime(string value, string? path) { try { @@ -512,11 +512,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateTime)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.DateTime)}'.", exception); } } - public static global::System.DateTimeOffset ParseSystemDateTimeOffset(string value, Func getPath) + public static global::System.DateTimeOffset ParseSystemDateTimeOffset(string value, string? path) { try { @@ -524,11 +524,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateTimeOffset)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.DateTimeOffset)}'.", exception); } } - public static decimal ParseDecimal(string value, Func getPath) + public static decimal ParseDecimal(string value, string? path) { try { @@ -536,11 +536,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(decimal)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(decimal)}'.", exception); } } - public static global::System.TimeSpan ParseSystemTimeSpan(string value, Func getPath) + public static global::System.TimeSpan ParseSystemTimeSpan(string value, string? path) { try { @@ -548,11 +548,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.TimeSpan)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.TimeSpan)}'.", exception); } } - public static global::System.Guid ParseSystemGuid(string value, Func getPath) + public static global::System.Guid ParseSystemGuid(string value, string? path) { try { @@ -560,11 +560,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Guid)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Guid)}'.", exception); } } - public static global::System.Uri ParseSystemUri(string value, Func getPath) + public static global::System.Uri ParseSystemUri(string value, string? path) { try { @@ -572,11 +572,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Uri)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Uri)}'.", exception); } } - public static global::System.Version ParseSystemVersion(string value, Func getPath) + public static global::System.Version ParseSystemVersion(string value, string? path) { try { @@ -584,11 +584,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Version)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Version)}'.", exception); } } - public static global::System.Int128 ParseSystemInt128(string value, Func getPath) + public static global::System.Int128 ParseSystemInt128(string value, string? path) { try { @@ -596,11 +596,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Int128)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Int128)}'.", exception); } } - public static global::System.Half ParseSystemHalf(string value, Func getPath) + public static global::System.Half ParseSystemHalf(string value, string? path) { try { @@ -608,11 +608,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Half)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.Half)}'.", exception); } } - public static global::System.UInt128 ParseSystemUInt128(string value, Func getPath) + public static global::System.UInt128 ParseSystemUInt128(string value, string? path) { try { @@ -620,11 +620,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.UInt128)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.UInt128)}'.", exception); } } - public static global::System.DateOnly ParseSystemDateOnly(string value, Func getPath) + public static global::System.DateOnly ParseSystemDateOnly(string value, string? path) { try { @@ -632,11 +632,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateOnly)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.DateOnly)}'.", exception); } } - public static global::System.TimeOnly ParseSystemTimeOnly(string value, Func getPath) + public static global::System.TimeOnly ParseSystemTimeOnly(string value, string? path) { try { @@ -644,11 +644,11 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.TimeOnly)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(global::System.TimeOnly)}'.", exception); } } - public static byte[] ParseByteArray(string value, Func getPath) + public static byte[] ParseByteArray(string value, string? path) { try { @@ -656,7 +656,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte[])}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(byte[])}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T.generated.txt index b26d7ebc0bc32..c7a8191aa6e94 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T.generated.txt @@ -91,7 +91,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -102,7 +102,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -146,7 +146,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -237,7 +237,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -245,7 +245,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_BinderOptions.generated.txt index 89d3a8714e2fc..e7ebd66c7b8cf 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_BinderOptions.generated.txt @@ -91,7 +91,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -102,7 +102,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -146,7 +146,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -237,7 +237,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -245,7 +245,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name.generated.txt index eb23ee05417bb..63fd389cb721a 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name.generated.txt @@ -91,7 +91,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -102,7 +102,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -146,7 +146,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -237,7 +237,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -245,7 +245,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name_BinderOptions.generated.txt index d2a398bbc9042..b95cb9ae0e954 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Configure_T_name_BinderOptions.generated.txt @@ -85,7 +85,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration { if (section.Value is string value) { - instance.Add(ParseInt(value, () => section.Path)); + instance.Add(ParseInt(value, section.Path)); } } } @@ -96,7 +96,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value1) { - instance.MyInt = ParseInt(value1, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value1, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -140,7 +140,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["MyInt"] is string value4) { - instance.MyInt = ParseInt(value4, () => configuration.GetSection("MyInt").Path); + instance.MyInt = ParseInt(value4, configuration.GetSection("MyInt").Path); } else if (defaultValueIfNotFound) { @@ -231,7 +231,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -239,7 +239,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/UnsupportedTypes.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/UnsupportedTypes.generated.txt index e4390c7ada0e0..8becba5ac74ca 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/UnsupportedTypes.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/UnsupportedTypes.generated.txt @@ -131,7 +131,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration if (configuration["Age"] is string value3) { - instance.Age = ParseInt(value3, () => configuration.GetSection("Age").Path); + instance.Age = ParseInt(value3, configuration.GetSection("Age").Path); } else if (defaultValueIfNotFound) { @@ -168,7 +168,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration int x = (int)(10); if (configuration["x"] is string value13) { - x = ParseInt(value13, () => configuration.GetSection("x").Path); + x = ParseInt(value13, configuration.GetSection("x").Path); } return new global::Record(x) @@ -236,7 +236,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration return binderOptions; } - public static int ParseInt(string value, Func getPath) + public static int ParseInt(string value, string? path) { try { @@ -244,7 +244,7 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration } catch (Exception exception) { - throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception); + throw new InvalidOperationException($"Failed to convert configuration value at '{path}' to type '{typeof(int)}'.", exception); } } #endregion Core binding extensions.