~ruther/NosSmooth

ref: 115ea2fe6d4b36561e951748004497bb841cf499 NosSmooth/Packets/NosSmooth.PacketSerializer/Extensions/ResultExtensions.cs -rw-r--r-- 1.0 KiB
115ea2fe — Rutherther chore: update dependencies 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
//  ResultExtensions.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Remora.Results;

namespace NosSmooth.Packets.Extensions;

/// <summary>
/// Extensions for <see cref="Result{TEntity}"/> class.
/// </summary>
public static class ResultExtensions
{
    /// <summary>
    /// Cast the given non-nullable result type to another type.
    /// </summary>
    /// <param name="result">The result to cast.</param>
    /// <typeparam name="TTo">The type to cast to.</typeparam>
    /// <typeparam name="TFrom">The type to cast from.</typeparam>
    /// <returns>The casted result.</returns>
    public static Result<TTo> Cast<TTo, TFrom>(this Result<TFrom> result)
        where TTo : notnull
        where TFrom : notnull
    {
        if (!result.IsSuccess)
        {
            return Result<TTo>.FromError(result);
        }

        return Result<TTo>.FromSuccess((TTo)(object)result.Entity);
    }
}
Do not follow this link