mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 05:48:14 +08:00
Add Spectre.Cli to Spectre.Console
* Renames Spectre.Cli to Spectre.Console.Cli. * Now uses Verify with Spectre.Console.Cli tests. * Removes some duplicate definitions. Closes #168
This commit is contained in:

committed by
Patrik Svensson

parent
0bbf9b81a9
commit
0ae419326d
31
src/Spectre.Console/Cli/Internal/CommandBinder.cs
Normal file
31
src/Spectre.Console/Cli/Internal/CommandBinder.cs
Normal file
@ -0,0 +1,31 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user