public static CommandValueLookup GetParameterValues(CommandTree?tree, ITypeResolver resolver) { var lookup = new CommandValueLookup(); var binder = new CommandValueBinder(lookup); CommandValidator.ValidateRequiredParameters(tree); while (tree != null) { // Process unmapped parameters. foreach (var parameter in tree.Unmapped) { if (parameter.IsFlagValue()) { // Set the flag value to an empty, not set instance. var instance = Activator.CreateInstance(parameter.ParameterType); lookup.SetValue(parameter, instance); } else { // Is this an option with a default value? if (parameter is CommandOption option && option.DefaultValue != null) { binder.Bind(parameter, resolver, option.DefaultValue?.Value); CommandValidator.ValidateParameter(parameter, lookup); } } } // Process mapped parameters. foreach (var mapped in tree.Mapped) { if (mapped.Parameter.WantRawValue) { // Just try to assign the raw value. binder.Bind(mapped.Parameter, resolver, mapped.Value); } else { var converter = GetConverter(lookup, binder, resolver, mapped.Parameter); if (converter == null) { throw RuntimeException.NoConverterFound(mapped.Parameter); } if (mapped.Parameter.IsFlagValue() && mapped.Value == null) { if (mapped.Parameter is CommandOption option && option.DefaultValue != null) { // Set the default value. binder.Bind(mapped.Parameter, resolver, option.DefaultValue?.Value); } else { // Set the flag but not the value. binder.Bind(mapped.Parameter, resolver, null); } }