From 2d31af777d1decd4486d29cb72e37ded777eff8c Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Wed, 11 Dec 2024 11:34:41 +0800 Subject: [PATCH] =?UTF-8?q?1.=20**`Entity.cs`=EF=BC=88`NetCorePal.Extensio?= =?UTF-8?q?ns.Domain`=20=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=EF=BC=89**=20?= =?UTF-8?q?=20=20=20-=20=E5=9C=A8=20`Entity`=20=E7=B1=BB=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20`ToString`=20=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=8B=BC=E6=8E=A5?= =?UTF-8?q?=E3=80=82=20=20=20=20-=20=E5=B0=86=20`=5FdomainEvents`=20?= =?UTF-8?q?=E7=9A=84=E5=88=9D=E5=A7=8B=E5=8C=96=E6=96=B9=E5=BC=8F=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20`=E9=9B=86=E5=90=88=E8=A1=A8=E8=BE=BE=E5=BC=8F`?= =?UTF-8?q?=E3=80=82=20=20=20=20-=20=E5=B0=86=20`AddDomainEvent`=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E8=AE=BF=E9=97=AE=E4=BF=AE=E9=A5=B0?= =?UTF-8?q?=E7=AC=A6=E4=BB=8E=20`public`=20=E4=BF=AE=E6=94=B9=E4=B8=BA=20`?= =?UTF-8?q?protected`=EF=BC=8C=E5=A2=9E=E5=BC=BA=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E6=80=A7=EF=BC=8C=E9=99=90=E5=88=B6=E5=A4=96=E9=83=A8=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E3=80=82=20=20=20=20-=20=E5=9C=A8=20`Entity`=20?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=EF=BC=8C=20`GetKeys`=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8=20`=E9=9B=86?= =?UTF-8?q?=E5=90=88=E8=A1=A8=E8=BE=BE=E5=BC=8F`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2. **`PagedData.cs`(`NetCorePal.Extensions.Domain` 命名空间)** - 在 `PagedData` 类中新增无参构造函数。 --- src/Domain.Abstractions/Entity.cs | 6 +++--- src/NetCorePal.Extensions.Dto/PagedData.cs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Domain.Abstractions/Entity.cs b/src/Domain.Abstractions/Entity.cs index dcaf4592..82985bcf 100644 --- a/src/Domain.Abstractions/Entity.cs +++ b/src/Domain.Abstractions/Entity.cs @@ -13,10 +13,10 @@ public abstract class Entity public override string ToString() => $"[Entity: {GetType().Name}] Keys = {string.Join(",", GetKeys())}"; - private readonly List _domainEvents = new(); + private readonly List _domainEvents = []; public IReadOnlyList GetDomainEvents() => _domainEvents.AsReadOnly(); - public void AddDomainEvent(IDomainEvent eventItem) + protected void AddDomainEvent(IDomainEvent eventItem) { _domainEvents.Add(eventItem); } @@ -35,7 +35,7 @@ public abstract class Entity : Entity where TKey : notnull #pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 public virtual TKey Id { get; protected set; } #pragma warning restore CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 - public override object[] GetKeys() => new object[] { Id }; + public override object[] GetKeys() => [Id]; public override bool Equals(object? obj) { diff --git a/src/NetCorePal.Extensions.Dto/PagedData.cs b/src/NetCorePal.Extensions.Dto/PagedData.cs index 7b04dafd..21e15942 100644 --- a/src/NetCorePal.Extensions.Dto/PagedData.cs +++ b/src/NetCorePal.Extensions.Dto/PagedData.cs @@ -1,4 +1,6 @@ -namespace NetCorePal.Extensions.Dto; +using System.Text.Json.Serialization; + +namespace NetCorePal.Extensions.Dto; /// /// 分页数据模型 @@ -13,6 +15,7 @@ public class PagedData /// 总数据条数 /// 当前页码,从1开始 /// 每页条数 + [JsonConstructor] public PagedData(IEnumerable items, int total, int pageIndex, int pageSize) { Items = items; @@ -20,18 +23,27 @@ public PagedData(IEnumerable items, int total, int pageIndex, int pageSize) PageIndex = pageIndex; PageSize = pageSize; } + + public PagedData() + { + Items = []; + } + /// /// 分页数据 /// public IEnumerable Items { get; private set; } + /// /// 数据总数 /// public int Total { get; private set; } + /// /// 当前页码,从1开始 /// public int PageIndex { get; private set; } + /// /// 每页数据条数 ///