-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-Extensions-Configurationsource-generatorIndicates an issue with a source generator featureIndicates an issue with a source generator feature
Milestone
Description
from @eerhardt in #82179 (comment) (fyi @stephentoub)
A couple things here:
Parsing:
- In order to be consistent with the reflection based behavior, we need to catch the int.Parse exception thrown here, and wrap it in a
InvalidOperationExceptionand add the configuration path of the invalid data. This allows devs to easily know where the invalid data exists from the exception message.- This should be
int.Parse(valueString, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);See the following for how I did it when manually writing the bind code for Console Logging:
runtime/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerOptions.cs
Lines 222 to 239 in 967250c
internal static bool ParseInt(IConfiguration configuration, string key, out int value) { if (configuration[key] is string valueString) { try { value = int.Parse(valueString, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); return true; } catch (Exception e) { ThrowInvalidConfigurationException(configuration, key, typeof(int), e); } } value = default; return false; }
Metadata
Metadata
Assignees
Labels
area-Extensions-Configurationsource-generatorIndicates an issue with a source generator featureIndicates an issue with a source generator feature