MrDave1999 / SimpleResults

A simple library to implement the Result pattern for returning from services
https://mrdave1999.github.io/SimpleResults
MIT License
105 stars 2 forks source link

Add methods to execute explicit conversions #34

Closed MrDave1999 closed 1 year ago

MrDave1999 commented 1 year ago

Methods to be added in the Result class to perform the conversion from Result to:

public Result<T> ToResult<T>(T data);
public ListedResult<T> ToListedResult<T>(IEnumerable<T> data);
public PagedResult<T> ToPagedResult<T>(IEnumerable<T> data, PagedInfo pagedInfo);

These methods can go in a file named Result.Conversions.cs. Note: Implicit operators can call these methods.

Usage

var person = new Person { Name = "Bob" };
Result invalidResult = Result.Invalid();
Result<Person> result = invalidResult.ToResult(person);

PD: These methods have been added.