add some default types to de-duplicate similar implmentations
This commit is contained in:
36
Pilz.Net/Extensions/ApiMessageExtensions.cs
Normal file
36
Pilz.Net/Extensions/ApiMessageExtensions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Pilz.Net.Api;
|
||||
using Pilz.Net.Api.Messages;
|
||||
|
||||
namespace Pilz.Net.Extensions;
|
||||
|
||||
public static class ApiMessageExtensions
|
||||
{
|
||||
public static ApiResult ToItemResult<T>(this T? @this)
|
||||
{
|
||||
if (@this == null)
|
||||
return ApiResult.NotFound();
|
||||
return ApiResult.Ok(@this.ToItemMsg());
|
||||
}
|
||||
|
||||
public static ApiResult ToItemsResult<T>(this IEnumerable<T>? @this)
|
||||
{
|
||||
if (@this == null)
|
||||
return ApiResult.NotFound();
|
||||
return ApiResult.Ok(@this.ToItemsMsg());
|
||||
}
|
||||
|
||||
public static GeneralItemMessages<T>.Item ToItemMsg<T>(this T @this)
|
||||
{
|
||||
return new GeneralItemMessages<T>.Item(@this);
|
||||
}
|
||||
|
||||
public static GeneralItemMessages<T>.Items ToItemsMsg<T>(this IEnumerable<T> @this)
|
||||
{
|
||||
return new GeneralItemMessages<T>.Items([.. @this]);
|
||||
}
|
||||
|
||||
public static GeneralItemMessages<T>.Items ToItemsMsg<T>(this T[] @this)
|
||||
{
|
||||
return new GeneralItemMessages<T>.Items([.. @this]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user