mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
(#555) Clarify ITypeResolver returns null
and does not throw on unresolvable types. Also changed the TypeResolverAdapter to adhere to those expectations and removed the now no longer needed try-catch from CommandPropertyBinder.
This commit is contained in:

committed by
Patrik Svensson

parent
21ac952307
commit
2f6b4f53c4
@ -11,7 +11,7 @@ namespace Spectre.Console.Cli
|
||||
/// Resolves an instance of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to resolve.</param>
|
||||
/// <returns>An instance of the specified type.</returns>
|
||||
/// <returns>An instance of the specified type, or <c>null</c> if no registration for the specified type exists.</returns>
|
||||
object? Resolve(Type? type);
|
||||
}
|
||||
}
|
||||
|
@ -28,16 +28,9 @@ namespace Spectre.Console.Cli
|
||||
|
||||
private static CommandSettings CreateSettings(ITypeResolver resolver, Type settingsType)
|
||||
{
|
||||
try
|
||||
if (resolver.Resolve(settingsType) is CommandSettings settings)
|
||||
{
|
||||
if (resolver.Resolve(settingsType) is CommandSettings settings)
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
return settings;
|
||||
}
|
||||
|
||||
if (Activator.CreateInstance(settingsType) is CommandSettings instance)
|
||||
|
@ -20,14 +20,9 @@ namespace Spectre.Console.Cli
|
||||
|
||||
try
|
||||
{
|
||||
if (_resolver != null)
|
||||
var obj = _resolver?.Resolve(type);
|
||||
if (obj != null)
|
||||
{
|
||||
var obj = _resolver.Resolve(type);
|
||||
if (obj == null)
|
||||
{
|
||||
throw CommandRuntimeException.CouldNotResolveType(type);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user