Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dohlenaugur opened this issue Aug 2, 2024 · 0 comments
Open

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

dohlenaugur opened this issue Aug 2, 2024 · 0 comments

Comments

@dohlenaugur
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant