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 CommandParameterParser

Remarks

CommandParameterParser maintains a static Dictionary<Type, CommandParameterParser> mapping each supported type to its parser instance. Built-in parsers are registered in the static constructor:

Type
Parser Behavior

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

Goal
How

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

circle-exclamation

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

circle-exclamation
circle-exclamation
circle-exclamation
circle-info

Float parser is locale-aware The float parser replaces commas with dots before parsing, handling European-style decimal separators (3,143.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