Class CommandParameters
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
initialParametersDictionary<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
this[string]
Gets or sets a parameter value by key.
public object? this[string key] { get; set; }
Parameters
keystringThe parameter key.
Property Value
- object
The parameter value, or
nullif 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
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
requiredKeysstring[]The parameter keys that are required.
Returns
GetParameter(string)
Gets a parameter value as an untyped object.
public object? GetParameter(string key)
Parameters
keystringThe parameter key.
Returns
- object
The parameter value, or
nullif the key is not present.
GetParameter<T>(string)
Gets a typed parameter value.
public T? GetParameter<T>(string key)
Parameters
keystringThe parameter key.
Returns
- T
The parameter value converted to
T, or the default value ofTif not found or not convertible.
Type Parameters
TThe 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
keystringThe parameter key.
Returns
- T
The parameter value converted to
T.
Type Parameters
TThe 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
keystringThe parameter key.
Returns
- bool
trueif 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
keystringThe parameter key.
Returns
- bool
trueif 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
otherCommandParametersThe 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
keystringThe parameter key.
Returns
- bool
trueif the parameter was removed; otherwise,false.
SetParameter(string, object?)
Sets a parameter value.
public CommandParameters SetParameter(string key, object? value)
Parameters
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
requiredKeysstring[]The parameter keys that are required.
Returns
- bool
trueif all required parameters are present; otherwise,false.