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
-
Result<T>
- 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
stringThe 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
Message
Gets the message associated with this result, which may describe success or error details.
public string Message { get; protected set; }
Property Value
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
stringThe message template for structured logging
logLevel
LogEventLevelThe log level for the error (defaults to Error)
callerFilePath
stringThe file path of the caller (automatically captured)
callerLineNumber
intThe 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
stringThe message template for structured logging with placeholders
prop0
objectThe property value for the message template
logLevel
LogEventLevelThe log level for the error (defaults to Error)
callerFilePath
stringThe file path of the caller (automatically captured)
callerLineNumber
intThe 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
stringThe message template for structured logging with placeholders
prop0
objectThe first property value for the message template
prop1
objectThe second property value for the message template
logLevel
LogEventLevelThe log level for the error (defaults to Error)
callerFilePath
stringThe file path of the caller (automatically captured)
callerLineNumber
intThe 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
stringThe message template for structured logging with placeholders
prop0
objectThe first property value for the message template
prop1
objectThe second property value for the message template
prop2
objectThe third property value for the message template
logLevel
LogEventLevelThe log level for the error (defaults to Error)
callerFilePath
stringThe file path of the caller (automatically captured)
callerLineNumber
intThe 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
stringAn 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
TThe value to wrap in a successful result
message
stringAn 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.ResultErrorThe error information to convert to a failed result
Returns
- Result
A failed Result with the error message