//
// 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;
///
/// Extensions for class.
///
public static class ResultExtensions
{
///
/// Cast the given non-nullable result type to another type.
///
/// The result to cast.
/// The type to cast to.
/// The type to cast from.
/// The casted result.
public static Result Cast(this Result result)
where TTo : notnull
where TFrom : notnull
{
if (!result.IsSuccess)
{
return Result.FromError(result);
}
return Result.FromSuccess((TTo)(object)result.Entity);
}
}