mirror of
https://github.com/Ikatono/ComiServ.git
synced 2025-10-28 20:45:35 -05:00
API mostly working, starting to work on webapp
This commit is contained in:
32
Models/Truncated.cs
Normal file
32
Models/Truncated.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Reflection.PortableExecutable;
|
||||
|
||||
namespace ComiServ.Models
|
||||
{
|
||||
public class Truncated<T>
|
||||
{
|
||||
public int Max { get; }
|
||||
public int Count { get; }
|
||||
public bool Complete { get; }
|
||||
public List<T> Items { get; }
|
||||
public Truncated(int max, IEnumerable<T> items)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
Max = max;
|
||||
Items = items.Take(max+1).ToList();
|
||||
if (Items.Count <= max)
|
||||
{
|
||||
Complete = true;
|
||||
if (Items.Count > 0)
|
||||
Items.RemoveAt(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
Complete = false;
|
||||
}
|
||||
Count = Items.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user