Open KathleenDollard opened 3 months ago
returns the types
default
value if the key is in the corresponding collection when the user entered the value.
That seems backwards. How does the application get the user-specified value rather than default
?
public Result TryGetValueResult(Symbol key, out T result); public Result TryGetValueResult(string key, out T result); public Result GetValueResult(Symbol key); public Result GetValueResult(string key);
Should those instead be
-public Result TryGetValueResult(Symbol key, out T result);
+public bool TryGetValueResult(Symbol key, out ValueResult result);
-public Result TryGetValueResult(string key, out T result);
+public bool TryGetValueResult(string key, out ValueResult result);
-public Result GetValueResult(Symbol key);
+public ValueResult GetValueResult(Symbol key);
-public Result GetValueResult(string key);
+public ValueResult GetValueResult(string key);
How do subsystems create instances of ValueResult? No constructors are listed but there are readonly properties.
CLI authors will be able to retrieve values for symbols from the
ParseResult
or theValueSubsystem
. TheValueSubsystem
is discussed in #2357, which focuses primarily on how default values are handled.CLI authors that are using the core parser directly (no help, etc) can retrieve values from the
ParseResult
. When the pipeline is used, the values can be retrieved from theValueSubsystem
. The differences are:(*) The default value for the type is returned.
This is consistent with the core parser providing minimum functionality that is fixed over time, and subsystems that can evolve in the future to provide solutions for known default features like getting defaults from environment variables.
The API for the
ParseResult
and theValueSubsystem
will be the same:The
GetValue
method throws if the key (usually a string) is not in the collection, and returns the typesdefault
value if the key is in the corresponding collection when the user entered the value.Question: Does
GetValue
throw or return default onHasError
? Probably preserve current behavior. Question: DoesTryGetValue
return false onHasError
? Seems appropriate.Both
ParseResult
and theValueSubsystem
also provide access to the underlyingValueResult
object:ValueResult
is an immutable type that allows access to theLocation
,Symbol
and other details about how the value was created. Note that while theError
reference is not changeable, errors can be added to the error collection.I greatly wish we had generic indexers. :-(