* Throw exceptions by default (#133)

* Doc strings for SieveOptions.cs
* Simplify MaxPageSize calculation

Co-authored-by: ITDancer139 <kevinitdancersommer@gmail.com>
This commit is contained in:
ITDancer13 2021-05-15 18:06:40 +02:00 committed by GitHub
parent 8bd9ce85d9
commit 2c9d907764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -2,12 +2,26 @@
{
public class SieveOptions
{
/// <summary>
/// If flag is set, property names have to match including case sensitivity.
/// </summary>
public bool CaseSensitive { get; set; } = false;
/// <summary>
/// Fallback value of no page size is specified in the request.
/// </summary>
public int DefaultPageSize { get; set; } = 0;
/// <summary>
/// Specifies the upper limit of a page size to be requested.
/// </summary>
/// <remarks>Values less or equal to 0 are ignored.</remarks>
public int MaxPageSize { get; set; } = 0;
public bool ThrowExceptions { get; set; } = false;
/// <summary>
/// If flag is set, Sieve throws exception otherwise exceptions are caught and the already processed
/// result is returned.
/// </summary>
public bool ThrowExceptions { get; set; } = true;
}
}
}

View File

@ -377,7 +377,11 @@ namespace Sieve.Services
{
var page = model?.Page ?? 1;
var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize;
var maxPageSize = _options.Value.MaxPageSize > 0 ? _options.Value.MaxPageSize : pageSize;
if (_options.Value.MaxPageSize > 0)
{
pageSize = Math.Min(pageSize, _options.Value.MaxPageSize);
}
if (pageSize <= 0)
{
@ -385,7 +389,7 @@ namespace Sieve.Services
}
result = result.Skip((page - 1) * pageSize);
result = result.Take(Math.Min(pageSize, maxPageSize));
result = result.Take(page);
return result;
}