-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from nblumhardt/complex-props
Use consistent binding logic for nested properties in object argument values
- Loading branch information
Showing
7 changed files
with
295 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationArgumentValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Reflection; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Serilog.Settings.Configuration; | ||
|
||
abstract class ConfigurationArgumentValue | ||
{ | ||
public abstract object? ConvertTo(Type toType, ResolutionContext resolutionContext); | ||
|
||
public static ConfigurationArgumentValue FromSection(IConfigurationSection argumentSection, IReadOnlyCollection<Assembly> configurationAssemblies) | ||
{ | ||
ConfigurationArgumentValue argumentValue; | ||
|
||
// Reject configurations where an element has both scalar and complex | ||
// values as a result of reading multiple configuration sources. | ||
if (argumentSection.Value != null && argumentSection.GetChildren().Any()) | ||
throw new InvalidOperationException( | ||
$"The value for the argument '{argumentSection.Path}' is assigned different value " + | ||
"types in more than one configuration source. Ensure all configurations consistently " + | ||
"use either a scalar (int, string, boolean) or a complex (array, section, list, " + | ||
"POCO, etc.) type for this argument value."); | ||
|
||
if (argumentSection.Value != null) | ||
{ | ||
argumentValue = new StringArgumentValue(argumentSection.Value); | ||
} | ||
else | ||
{ | ||
argumentValue = new ObjectArgumentValue(argumentSection, configurationAssemblies); | ||
} | ||
|
||
return argumentValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
src/Serilog.Settings.Configuration/Settings/Configuration/IConfigurationArgumentValue.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.