Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Created January 31, 2023 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swimburger/c65a48a3b6034f063876608b48bf9847 to your computer and use it in GitHub Desktop.
Save Swimburger/c65a48a3b6034f063876608b48bf9847 to your computer and use it in GitHub Desktop.
Replace empty strings with `null` recursively in .NET configuration sections
private static void ChangeEmptyStringToNull(IConfigurationSection configSection)
{
if (configSection == null) return;
if (configSection.Value == "") configSection.Value = null;
foreach (var childConfigSection in configSection.GetChildren())
{
ChangeEmptyStringToNull(childConfigSection);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment