Unity
1
Вклад в тег
public static IEnumerable<IEnumerable<T>> Split<T>(
this IEnumerable<T> source,
int count)
{
return source
.Select((x, y) => new { Index = y, Value = x })
.GroupBy(x => x.Index / count)
.Select(x => x.Select(y => y.Value).ToList())
.ToList();
}
/*
* ...to startup
* app.UseMiddleware<AnsHttpExceptionHandler>();
*/
public class MyHttpException(HttpStatusCode statusCode) : Exception
{
public HttpStatusCode StatusCode { get; set; } = statusCode;
}
public class MyHttpExceptionHandler(RequestDelegate pipeline)
{
private readonly RequestDelegate request = pipeline;
public Task Invoke(HttpContext context) => return InvokeAsync(context);
async Task InvokeAsync(HttpContext context)
{
try { await request(context); }
catch (AnsHttpException exception)
{
context.Response.StatusCode = (int)exception.StatusCode;
context.Response.Headers.Clear();
}
}
}
@{
throw new MyHttpException(HttpStatusCode.NotFound);
}