Table of Contents

Class Result

Namespace
Htmx.Components.Models
Assembly
Htmx.Components.dll

Represents the result of an operation with success/error status and an optional message. This class provides a way to return both success and error states with descriptive messages, along with structured logging capabilities for error scenarios.

public class Result
Inheritance
Result
Derived
Inherited Members
Extension Methods

Remarks

This design helps avoid exceptions for expected error conditions and provides better type inference compared to always using the generic Result<T> class.

Constructors

Result(string)

Initializes a new instance of the Result class with the specified message.

public Result(string message)

Parameters

message string

The message describing the result

Properties

IsError

Gets a value indicating whether this result represents an error condition.

public bool IsError { get; protected set; }

Property Value

bool

Message

Gets the message associated with this result, which may describe success or error details.

public string Message { get; protected set; }

Property Value

string

Methods

Error(string, LogEventLevel, string, int)

Creates an error result with structured logging capabilities. Logs the error message at the specified level and captures caller information for debugging.

public static Result.ResultError Error(string messageTemplate, LogEventLevel logLevel = LogEventLevel.Error, string callerFilePath = "", int callerLineNumber = 0)

Parameters

messageTemplate string

The message template for structured logging

logLevel LogEventLevel

The log level for the error (defaults to Error)

callerFilePath string

The file path of the caller (automatically captured)

callerLineNumber int

The line number of the caller (automatically captured)

Returns

Result.ResultError

A ResultError that can be implicitly converted to a failed Result

Error(string, object, LogEventLevel, string, int)

Creates an error result with structured logging capabilities and one template parameter. Logs the error message at the specified level and captures caller information for debugging.

public static Result.ResultError Error(string messageTemplate, object prop0, LogEventLevel logLevel = LogEventLevel.Error, string callerFilePath = "", int callerLineNumber = 0)

Parameters

messageTemplate string

The message template for structured logging with placeholders

prop0 object

The property value for the message template

logLevel LogEventLevel

The log level for the error (defaults to Error)

callerFilePath string

The file path of the caller (automatically captured)

callerLineNumber int

The line number of the caller (automatically captured)

Returns

Result.ResultError

A ResultError that can be implicitly converted to a failed Result

Error(string, object, object, LogEventLevel, string, int)

Creates an error result with structured logging capabilities and two template parameters. Logs the error message at the specified level and captures caller information for debugging.

public static Result.ResultError Error(string messageTemplate, object prop0, object prop1, LogEventLevel logLevel = LogEventLevel.Error, string callerFilePath = "", int callerLineNumber = 0)

Parameters

messageTemplate string

The message template for structured logging with placeholders

prop0 object

The first property value for the message template

prop1 object

The second property value for the message template

logLevel LogEventLevel

The log level for the error (defaults to Error)

callerFilePath string

The file path of the caller (automatically captured)

callerLineNumber int

The line number of the caller (automatically captured)

Returns

Result.ResultError

A ResultError that can be implicitly converted to a failed Result

Error(string, object, object, object, LogEventLevel, string, int)

Creates an error result with structured logging capabilities and three template parameters. Logs the error message at the specified level and captures caller information for debugging.

public static Result.ResultError Error(string messageTemplate, object prop0, object prop1, object prop2, LogEventLevel logLevel = LogEventLevel.Error, string callerFilePath = "", int callerLineNumber = 0)

Parameters

messageTemplate string

The message template for structured logging with placeholders

prop0 object

The first property value for the message template

prop1 object

The second property value for the message template

prop2 object

The third property value for the message template

logLevel LogEventLevel

The log level for the error (defaults to Error)

callerFilePath string

The file path of the caller (automatically captured)

callerLineNumber int

The line number of the caller (automatically captured)

Returns

Result.ResultError

A ResultError that can be implicitly converted to a failed Result

Ok(string)

Creates a successful result with an optional message.

public static Result Ok(string message = "")

Parameters

message string

An optional message describing the successful result

Returns

Result

A successful Result with the specified message

Value<T>(T, string)

Creates a successful result with a typed value and optional message. This method provides type inference to avoid having to specify the generic type parameter explicitly.

public static Result<T> Value<T>(T value, string message = "")

Parameters

value T

The value to wrap in a successful result

message string

An optional message describing the successful result

Returns

Result<T>

A successful Result<T> containing the specified value

Type Parameters

T

The type of the value (inferred from the parameter)

Operators

implicit operator Result(ResultError)

Implicitly converts a ResultError to a failed Result. This allows for easy creation of error results without explicitly constructing the Result instance.

public static implicit operator Result(Result.ResultError error)

Parameters

error Result.ResultError

The error information to convert to a failed result

Returns

Result

A failed Result with the error message