ardalis / ardalis/Result

Conversion From Result to TResponse when TResponse is IResult

Open
#252 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

`public sealed class ValidationBehavior(IEnumerable> validators)
: IPipelineBehavior
where TResponse: IResult where TMessage:IMessage
{
private readonly IEnumerable> _validators = validators;

public async ValueTask Handle(
TMessage message,
MessageHandlerDelegate next,
CancellationToken cancellationToken)
{
if (_validators.Any())
{
var errors = _validators.SelectMany(v => v.Validate(message).AsErrors()).ToArray();
if (errors.Length != 0)
{
try
{
return (TResponse)(object)Result.Invalid(errors);
}
catch
{
//*********************
}

}

}
return await next(message, cancellationToken);
}
}
`
"return (TResponse)(object)Result.Invalid(errors); " fails when TResponse is Result
is there a way to achieve the same result without using reflection

Contributor guide

Open the contributing guide

Research direction

Start with the ValidationBehavior entry point shown in the issue and inspect the conversion at `return (TResponse)(object)Result.Invalid(errors);`. Determine how invalid results should be represented when TResponse is `Result` or another IResult implementation, and consider the issue complete only when that conversion works without reflection.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.