mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-30 12:25:48 +08:00
Move Spectre.Console.Cli to it's own package
This commit is contained in:
committed by
Patrik Svensson
parent
b600832e00
commit
36ca22ffac
28
src/Spectre.Console.Cli/Internal/CommandBinder.cs
Normal file
28
src/Spectre.Console.Cli/Internal/CommandBinder.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Spectre.Console.Cli;
|
||||
|
||||
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