Class Reason<TReason>

Namespace
REslava.Result
Assembly
REslava.Result.dll
public abstract class Reason<TReason> : Reason, IReason, IReasonMetadata where TReason : Reason<TReason>

Type Parameters

TReason
Inheritance
Reason<TReason>
Implements
Derived
Inherited Members
Extension Methods

Constructors

Reason(string)

protected Reason(string message)

Parameters

message string

Reason(string, ImmutableDictionary<string, object>)

protected Reason(string message, ImmutableDictionary<string, object> tags)

Parameters

message string
tags ImmutableDictionary<string, object>

Reason(string, ImmutableDictionary<string, object>, ReasonMetadata)

protected Reason(string message, ImmutableDictionary<string, object> tags, ReasonMetadata metadata)

Parameters

message string
tags ImmutableDictionary<string, object>
metadata ReasonMetadata

Methods

CreateNew(string, ImmutableDictionary<string, object>)

Factory method for creating new instances (maintains immutability). Must be implemented by derived classes.

protected abstract TReason CreateNew(string message, ImmutableDictionary<string, object> tags)

Parameters

message string
tags ImmutableDictionary<string, object>

Returns

TReason

WithMessage(string)

Creates a new instance with updated message (immutable). Preserves existing Metadata.

public TReason WithMessage(string message)

Parameters

message string

Returns

TReason

WithMetadata(ReasonMetadata)

Creates a new instance with the specified metadata (immutable). Use this to attach or replace diagnostic/caller information.

public TReason WithMetadata(ReasonMetadata metadata)

Parameters

metadata ReasonMetadata

The metadata to attach. Null is treated as Empty.

Returns

TReason

WithTag(string, object)

Creates a new instance with an additional tag (immutable). Throws if key already exists. Preserves existing Metadata.

public TReason WithTag(string key, object value)

Parameters

key string
value object

Returns

TReason

WithTag<T>(TagKey<T>, T)

Creates a new instance with an additional typed tag (immutable). Throws if key already exists. Preserves existing Metadata.

public TReason WithTag<T>(TagKey<T> key, T value)

Parameters

key TagKey<T>
value T

Returns

TReason

Type Parameters

T

WithTags(params (string key, object value)[])

Creates a new instance with multiple additional tags (immutable). Throws if any key already exists. Preserves existing Metadata.

public TReason WithTags(params (string key, object value)[] tags)

Parameters

tags (string key, object value)[]

Returns

TReason

WithTagsFrom(ImmutableDictionary<string, object>)

Creates a new instance with additional tags from a dictionary (immutable). Throws if any key already exists. Preserves existing Metadata.

public TReason WithTagsFrom(ImmutableDictionary<string, object> tags)

Parameters

tags ImmutableDictionary<string, object>

Dictionary containing tags to add.

Returns

TReason

A new instance with the added tags.

Examples

var error = new ValidationError("Invalid input")
    .WithTagsFrom(new Dictionary<string, object>
    {
        ["Field"] = "Email",
        ["Value"] = "invalid-email"
    });