1. 创建类库放置实体

2. 创建文件夹Models,在文件夹中创建类BaseDto
public class BaseDto : INotifyPropertyChanged
public int Id { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
3.在文件夹中创建类DailyDto
public class DailyDto : BaseDto
set { title = value; OnPropertyChanged(); }
4. 在文件夹中创建类Page
public int PageIndex { get; set; }
public int PageSize { get; set; }
5.在类库创建类ToDoParameter
public class ToDoParameter : Page
public int? Status { get; set; }
6.在类库创建类IPagedList
public interface IPagedList<T>
bool HasPreviousPage { get; }
bool HasNextPage { get; }
7.在类库创建类PagedList
public class PagedList<T> : IPagedList<T>
public int PageIndex { get; set; }
public int PageSize { get; set; }
public int TotalCount { get; set; }
public int TotalPages { get; set; }
public int IndexFrom { get; set; }
public IList Items { get; set; }
public bool HasPreviousPage => PageIndex - IndexFrom > 0;
public bool HasNextPage => PageIndex - IndexFrom + 1 < TotalPages;
public PagedList(IEnumerable source, int pageIndex, int pageSize, int indexFrom)
if (indexFrom > pageIndex)
throw new ArgumentException($"indexFrom: {indexFrom} > pageIndex: {pageIndex}, must indexFrom <= pageIndex");
if (source is IQueryable querable)
TotalCount = querable.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
Items = querable.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToList();
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
Items = source.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToList();
public PagedList() => Items = new T[0];
public class PagedList<TSource, TResult> : IPagedList<TResult>
public int PageIndex { get; }
public int PageSize { get; }
public int TotalCount { get; }
public int TotalPages { get; }
public int IndexFrom { get; }
public IList Items { get; }
public bool HasPreviousPage => PageIndex - IndexFrom > 0;
public bool HasNextPage => PageIndex - IndexFrom + 1 < TotalPages;
public PagedList(IEnumerable source, Func, IEnumerable> converter, int pageIndex, int pageSize, int indexFrom)
if (indexFrom > pageIndex)
throw new ArgumentException($"indexFrom: {indexFrom} > pageIndex: {pageIndex}, must indexFrom <= pageIndex");
if (source is IQueryable querable)
TotalCount = querable.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
var items = querable.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToArray();
Items = new List(converter(items));
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
var items = source.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToArray();
Items = new List(converter(items));
public PagedList(IPagedList source, Func, IEnumerable> converter)
PageIndex = source.PageIndex;
PageSize = source.PageSize;
IndexFrom = source.IndexFrom;
TotalCount = source.TotalCount;
TotalPages = source.TotalPages;
Items = new List(converter(source.Items));
public static class PagedList
public static IPagedList<T> Empty<T>() => new PagedList();
public static IPagedList<TResult> From<TResult, TSource>(IPagedList source, Func, IEnumerable> converter) => new PagedList(source, converter);

8.在类库创建类ApiResponse
public ApiResponse(string title, bool status = false)
public ApiResponse(bool status, object result)
public string? Title { get; set; }
public bool Status { get; set; }
public object? Result { get; set; }
public class ApiResponse<T>
public bool Status { get; set; }
public T? Result { get; set; }