Skip to content

[Idea]: Common base type to use Results in generic Functions #216

@dohlenaugur

Description

@dohlenaugur

Hi,

I was wondering why there is no common base class or something like it, that allows one to use all similar functionalities of Result and Result.

I would like to do something like this:

public static T2 DoIfSuccess<T1, T2>(T1 input, Func function)
where T1 : IResultBase
where T2 : IResultBase
{
if (input.IsFailed) return input.ToResult();
var output = function();
return output.IsSuccess
? output
: input.ToResult();
}

It seems not to be possible at the moment, because T1 and T2 can not be converted into one another, but it should be possible in case of Result.Fail, because I don't need the value here.

Am I missing something? Why is this not possible currently and should it be possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions