mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00

* Renames Spectre.Cli to Spectre.Console.Cli. * Now uses Verify with Spectre.Console.Cli tests. * Removes some duplicate definitions. Closes #168
32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace Spectre.Console.Cli.Internal
|
|
{
|
|
internal static class CommandBinder
|
|
{
|
|
public static CommandSettings Bind(CommandTree? tree, Type settingsType, ITypeResolver resolver)
|
|
{
|
|
var lookup = CommandValueResolver.GetParameterValues(tree, resolver);
|
|
|
|
// Got a constructor with at least one name corresponding to a settings?
|
|
foreach (var constructor in settingsType.GetConstructors())
|
|
{
|
|
var parameters = constructor.GetParameters();
|
|
if (parameters.Length > 0)
|
|
{
|
|
foreach (var parameter in parameters)
|
|
{
|
|
if (lookup.HasParameterWithName(parameter?.Name))
|
|
{
|
|
// Use constructor injection.
|
|
return CommandConstructorBinder.CreateSettings(lookup, constructor, resolver);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return CommandPropertyBinder.CreateSettings(lookup, settingsType, resolver);
|
|
}
|
|
}
|
|
}
|