Table of Contents

Class CommandParameters

Namespace
Core.CliniCore.Commands
Assembly
Core.CliniCore.dll

Container for passing parameters to commands in a standardized way

public class CommandParameters
Inheritance
CommandParameters
Inherited Members

Constructors

CommandParameters()

Initializes a new instance of the CommandParameters class with no initial parameters.

public CommandParameters()

CommandParameters(Dictionary<string, object?>)

Initializes a new instance of the CommandParameters class with the specified initial parameters.

public CommandParameters(Dictionary<string, object?> initialParameters)

Parameters

initialParameters Dictionary<string, object>

The initial parameter values to populate the collection with.

Properties

Count

Gets the number of parameters in the collection.

public int Count { get; }

Property Value

int

this[string]

Gets or sets a parameter value by key.

public object? this[string key] { get; set; }

Parameters

key string

The parameter key.

Property Value

object

The parameter value, or null if the key is not found.

Methods

Clear()

Clears all parameters from the collection.

public void Clear()

Clone()

Creates a shallow copy of this CommandParameters instance.

public CommandParameters Clone()

Returns

CommandParameters

A new CommandParameters instance containing the same parameter values.

Create()

Creates a new, empty CommandParameters instance.

public static CommandParameters Create()

Returns

CommandParameters

A new CommandParameters object.

Create(string, object?)

Creates a new CommandParameters instance initialized with a single parameter.

public static CommandParameters Create(string key, object? value)

Parameters

key string

The parameter key.

value object

The parameter value.

Returns

CommandParameters

A new CommandParameters object containing the specified key and value.

GetKeys()

Gets all parameter keys.

public IEnumerable<string> GetKeys()

Returns

IEnumerable<string>

An enumerable collection of parameter keys.

GetMissingRequired(params string[])

Gets validation error messages for any missing required parameters.

public List<string> GetMissingRequired(params string[] requiredKeys)

Parameters

requiredKeys string[]

The parameter keys that are required.

Returns

List<string>

A list of error messages describing missing parameters.

GetParameter(string)

Gets a parameter value as an untyped object.

public object? GetParameter(string key)

Parameters

key string

The parameter key.

Returns

object

The parameter value, or null if the key is not present.

GetParameter<T>(string)

Gets a typed parameter value.

public T? GetParameter<T>(string key)

Parameters

key string

The parameter key.

Returns

T

The parameter value converted to T, or the default value of T if not found or not convertible.

Type Parameters

T

The expected parameter type.

GetRequiredParameter<T>(string)

Gets a required parameter value and throws an exception if it is missing or null.

public T GetRequiredParameter<T>(string key)

Parameters

key string

The parameter key.

Returns

T

The parameter value converted to T.

Type Parameters

T

The expected parameter type.

Exceptions

ArgumentException

Thrown when the parameter is missing or null.

HasParameter(string)

Determines whether the specified parameter key exists.

public bool HasParameter(string key)

Parameters

key string

The parameter key.

Returns

bool

true if the key exists; otherwise, false.

HasValue(string)

Determines whether the specified parameter key exists and has a non-null value.

public bool HasValue(string key)

Parameters

key string

The parameter key.

Returns

bool

true if the key exists and has a value; otherwise, false.

Merge(CommandParameters)

Merges another set of parameters into this instance, overwriting existing values with the same keys.

public CommandParameters Merge(CommandParameters other)

Parameters

other CommandParameters

The other parameter collection to merge.

Returns

CommandParameters

The current CommandParameters instance for method chaining.

RemoveParameter(string)

Removes the parameter with the specified key.

public bool RemoveParameter(string key)

Parameters

key string

The parameter key.

Returns

bool

true if the parameter was removed; otherwise, false.

SetParameter(string, object?)

Sets a parameter value.

public CommandParameters SetParameter(string key, object? value)

Parameters

key string

The parameter key.

value object

The parameter value.

Returns

CommandParameters

The current CommandParameters instance for method chaining.

ToString()

Returns a string that represents the current CommandParameters.

public override string ToString()

Returns

string

A formatted string containing all parameter key-value pairs.

ValidateRequired(params string[])

Validates that all required parameter keys are present and have non-null values.

public bool ValidateRequired(params string[] requiredKeys)

Parameters

requiredKeys string[]

The parameter keys that are required.

Returns

bool

true if all required parameters are present; otherwise, false.