© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
Kiel

❔ Reducing Result-pattern annoyances

I know Result patterns can be a bit controversial as far as their benefits, but I'm giving them a try in my project.
Anyways...I've outsourced some work to a scoped service which returns a Result<T>. My methods which call this outsourced code have this exact same structure:
var result = await service.DoSomethingAsync(...);
if (!result.IsSuccess)
    return Response(result.ErrorMessage);

var obj = result.Value;
// do stuff with obj
var result = await service.DoSomethingAsync(...);
if (!result.IsSuccess)
    return Response(result.ErrorMessage);

var obj = result.Value;
// do stuff with obj


Are there any ways to reduce this into a simpler form to further reduce the amount of code needed to perform the "try action, return error message if error else get success value" process? I certainly will concede I think I'm splitting hairs here and this is already simple enough for some, but I feel like I'm...missing something to make this more streamlined - maybe pattern matching could be utilized here?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ✅ ListView Annoyances.
C#CC# / help
3y ago
❔ Reducing commands
C#CC# / help
3y ago
❔ Reducing networking syscalls
C#CC# / help
4y ago
✅ Reducing exception usage, async methods
C#CC# / help
2y ago