Table of Contents

TRLS008 — Consider using Result.Combine

  • Severity: Info
  • Category: Trellis

What it detects

Flags conditional logic that manually combines two or more Result state checks, such as && chains over .IsSuccess or || chains over .IsFailure.

Why it matters

Result.Combine expresses intent more clearly and scales better than repeated manual branching.

Warning

Manual combination logic tends to duplicate error-selection code and becomes noisy as soon as you add a third or fourth result.

Bad example

using Trellis;

static class Example
{
    public static Result<int> Bad(Result<int> first, Result<int> second)
    {
        if (first.IsSuccess && second.IsSuccess)
        {
            first.TryGetValue(out var a);
            second.TryGetValue(out var b);
            return Result.Ok(a + b);
        }

        return first.IsFailure
            ? Result.Fail<int>(first.Error!)
            : Result.Fail<int>(second.Error!);
    }
}

Good example

using Trellis;

static class Example
{
    public static Result<int> Good(Result<int> first, Result<int> second) =>
        first
            .Combine(second)
            .Map((left, right) => left + right);
}

Code fix available

No.

Configuration

Use standard Roslyn configuration if you need to suppress this rule in a specific scope.

dotnet_diagnostic.TRLS008.severity = none
#pragma warning disable TRLS008
// Intentional: documented exception or test-only pattern.
#pragma warning restore TRLS008
Tip

Use Result.Combine(...) or .Combine(...) chaining, then continue with Map, Bind, or Match.