CommandParameterParser
Sealed, type-based parser registry that converts string inputs into typed objects. Provides built-in parsers for int, float, and string, with an internal API for registering custom parsers.
Definition
Namespace: Paragon.Core.Command Assembly: Paragon.dll
public sealed class CommandParameterParserRemarks
CommandParameterParser maintains a static Dictionary<Type, CommandParameterParser> mapping each supported type to its parser instance. Built-in parsers are registered in the static constructor:
int
Standard int.TryParse()
float
Strips trailing 'f', replaces ',' with '.', then float.TryParse()
string
Requires wrapping double quotes ("value"); returns the inner content
Custom parsers can be added via the internal RegisterParser<T>() method, which accepts a ParserDelegate<T> with the signature bool TryParse(string input, out T value).
Quick Lookup
Parse a string to typed value
CommandParameterParser.Parse(typeof(int), "42")
Try-parse with success check
CommandParameterParser.TryParse(typeof(float), "3.14", out var val)
Register custom parser
CommandParameterParser.RegisterParser<T>(tryParseFunc) (internal)
Methods
Parse
Parses a string input into the specified type.
type
Type
Target type to parse into
input
string
String representation of the value
Returns: The parsed value as object, or null/default if parsing fails.
TryParse
Attempts to parse a string input into the specified type.
type
Type
Target type to parse into
input
string
String representation of the value
value
out object
The parsed value if successful
Returns: true if parsing succeeded.
Throws KeyNotFoundException for unregistered types. If no parser is registered for the given type, this method throws rather than returning false.
Built-in Parsers
int
Standard int.TryParse():
float
Strips trailing 'f' suffix and replaces commas with dots before parsing:
string
Requires wrapping double quotes. Returns the inner content:
Common Pitfalls
String values must be double-quoted Unlike other parsers, the string parser requires the input to be wrapped in double quotes: "\"value\"". Unquoted strings return an empty string.
Unregistered types cause exceptions If Parse() or TryParse() is called with a type that has no registered parser, a KeyNotFoundException is thrown. There is no fallback or generic conversion.
Parse failures are silent When TryParse returns false, the output value is null. The caller (Command.Execute) still proceeds with this null value, which may cause unexpected behavior in the invoked command.
Float parser is locale-aware The float parser replaces commas with dots before parsing, handling European-style decimal separators (3,14 → 3.14).
Examples
Using Parse
Custom Parser Registration (internal)
See Also
CommandParameter — Delegates parsing to this class via
SetValueFromString()Command — Orchestrates parameter parsing during execution
CommandMethod — Contains the
CommandParameter[]array that uses this parser
Last updated