Table of Contents

Class CommandResult

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

Represents the result of a command execution.

public class CommandResult
Inheritance
CommandResult
Inherited Members

Properties

CommandId

Gets or sets the ID of the command that produced this result.

public Guid CommandId { get; set; }

Property Value

Guid

Data

Gets or sets any data returned by the command.

public object? Data { get; set; }

Property Value

object

ErrorMessage

Gets or sets error details if the command failed.

public string? ErrorMessage { get; set; }

Property Value

string

Exception

Gets or sets the exception that occurred during command execution, if any.

public Exception? Exception { get; set; }

Property Value

Exception

ExecutedAt

Gets or sets the date and time when the command was executed.

public DateTime ExecutedAt { get; set; }

Property Value

DateTime

ExecutionTime

Gets or sets the duration of the command execution.

public TimeSpan? ExecutionTime { get; set; }

Property Value

TimeSpan?

Message

Gets or sets a message describing the result of the command.

public string Message { get; set; }

Property Value

string

Success

Gets or sets a value indicating whether the command executed successfully.

public bool Success { get; set; }

Property Value

bool

ValidationErrors

Gets or sets the collection of validation errors produced during command execution.

public List<string> ValidationErrors { get; set; }

Property Value

List<string>

Warnings

Gets or sets the collection of warnings generated during command execution.

public List<string> Warnings { get; set; }

Property Value

List<string>

Methods

AddWarning(string)

Adds a warning message to the result.

public CommandResult AddWarning(string warning)

Parameters

warning string

The warning message to add.

Returns

CommandResult

The current CommandResult instance for method chaining.

Fail(string, Exception?)

Creates a failed CommandResult instance.

public static CommandResult Fail(string errorMessage, Exception? exception = null)

Parameters

errorMessage string

A message describing the cause of the failure.

exception Exception

The exception that triggered the failure, if available.

Returns

CommandResult

A configured CommandResult indicating failure.

GetData<T>()

Gets the primary data payload of the result, converted to the specified type.

public T? GetData<T>()

Returns

T

The data converted to T, or the default value of T if not set or not convertible.

Type Parameters

T

The expected type of the primary data.

GetData<T>(string)

Gets a named data value from the result.

public T? GetData<T>(string key)

Parameters

key string

The key associated with the stored value.

Returns

T

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

Type Parameters

T

The expected type of the stored value.

GetDisplayMessage()

Gets a user-friendly message summarizing the outcome of the command execution.

public string GetDisplayMessage()

Returns

string

A human-readable message that describes the result.

Ok(string, object?)

Creates a successful CommandResult instance.

public static CommandResult Ok(string message = "Command executed successfully.", object? data = null)

Parameters

message string

An optional message describing the success.

data object

Optional data returned by the command.

Returns

CommandResult

A configured CommandResult indicating success.

SetData(string, object?)

Sets a named data value in the result.

public CommandResult SetData(string key, object? value)

Parameters

key string

The key under which the data value is stored.

value object

The value to store.

Returns

CommandResult

The current CommandResult instance for method chaining.

ToString()

Returns a string that represents the current CommandResult.

public override string ToString()

Returns

string

A formatted string containing the success status and primary message.

Unauthorized(string)

Creates a CommandResult representing an authorization failure.

public static CommandResult Unauthorized(string message = "Unauthorized to execute this command.")

Parameters

message string

An optional message describing the authorization issue.

Returns

CommandResult

A configured CommandResult indicating unauthorized access.

ValidationFailed(List<string>)

Creates a CommandResult representing a validation failure.

public static CommandResult ValidationFailed(List<string> errors)

Parameters

errors List<string>

The collection of validation errors.

Returns

CommandResult

A configured CommandResult indicating validation failure.