Grace.Shared
1.0.0.10
dotnet add package Grace.Shared --version 1.0.0.10
NuGet\Install-Package Grace.Shared -Version 1.0.0.10
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Grace.Shared" Version="1.0.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Grace.Shared" Version="1.0.0.10" />
<PackageReference Include="Grace.Shared" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Grace.Shared --version 1.0.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Grace.Shared, 1.0.0.10"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Grace.Shared@1.0.0.10
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Grace.Shared&version=1.0.0.10
#tool nuget:?package=Grace.Shared&version=1.0.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Grace.Shared
基于 ABP(Volo.Abp)的通用 DTO、枚举、接口和业务模型的共享类库。
安装
dotnet add package Grace.Shared
内容
Records / DTOs
| 类型 | 描述 |
|---|---|
Avatar(string Origin) |
头像值对象,自动生成 Small(Origin_s)、Medium(Origin_m)、Origin 三个尺寸 |
BizItem(int Value, string Text) |
业务键值对 |
BizItem<T>(T Value, string Text) |
泛型业务键值对 |
AvatarBizItem<T>(T Value, string Text, string Avatar) |
带头像的业务键值对 |
UserSimpleProfile |
用户简要信息(Id、NickName、Avatar) |
DateTimeRange |
时间范围(BeginTime、EndTime) |
Coordinate(double Longitude, double Latitude) |
经纬度坐标(WGS-84) |
FileItem(string Url, string Name, string ContentType) |
文件元信息(地址、文件名、大小、MIME 类型) |
Enums
// 客户端平台
AppPlatform.Unknown = 0 // "未知"
AppPlatform.Android = 1 // "安卓"
AppPlatform.Ios = 2 // "苹果"
AppPlatform.WechatMiniProgram = 3 // "微信小程序"
AppPlatform.H5 = 5 // "H5"
// 性别
Gender.Unknown = 0 // "保密"
Gender.Male = 1 // "男"
Gender.Female = 2 // "女"
// 在线状态
OnlineStatus.Offline = 0 // "离线"
OnlineStatus.Online = 1 // "在线"
// 推送类型
PushType.Url = 1 // "跳转url"
PushType.Notice = 2 // "通知"
PushType.LaunchApp = 3 // "打开app"
// VIP
Vip.None = 0 // "普通会员"
Vip.VIP = 100 // "VIP"
Vip.SVIP = 200 // "超级VIP"
// 红包场景
RedPacketScene.Private = 100 // "私发红包"
RedPacketScene.Public = 200 // "群红包"
// 红包类型
RedPacketType.Lucky = 100 // "拼手气红包"
RedPacketType.Command = 200 // "口令红包"
RedPacketType.Normal = 300 // "普通红包"
// 启用/禁用
ActiveStatus.Disabled = 0 // "禁用"
ActiveStatus.Enabled = 1 // "启用"
// 是否判断
YesNo.No = 0 // "否"
YesNo.Yes = 1 // "是"
所有枚举均标注了 [Description],配合 Grace.Extensions 的 EnumExtension.GetDescription() 可直接获取中文描述。
Interfaces
public interface IHasActive { bool IsActive { get; } }
public interface IHasSearchKey { string SearchKey { get; } }
public interface IHasTimeRange { DateTimeRange? TimeRange { get; } }
public interface IHasSearchParameter
{
string SearchKey { get; }
DateTimeRange? TimeRange { get; }
}
适用于查询入参、实体等场景的通用接口。
Constants
MaxLenghtConst.L1 // 1
MaxLenghtConst.L255 // 255
MaxLenghtConst.L1024 // 1024
MaxLenghtConst.L4096 // 4096
定义了从 1 到 4096 共 18 个常用长度常量(1 / 2 / 5 / 10 / 15 / 20 / 36 / 50 / 100 / 128 / 200 / 255 / 512 / 1024 / 2048 / 4096),用于 DTO 属性 [MaxLength] 校验。
使用示例
using Grace.Shared;
using Grace.Enums;
// 头像处理
var avatar = new Avatar("https://example.com/avatar.jpg");
avatar.Small; // "https://example.com/avatar.jpg_s"
avatar.Medium; // "https://example.com/avatar.jpg_m"
// 业务键值对
var item = new BizItem(1, "活跃用户");
// 枚举 + Grace.Extensions 配合使用
Gender.Male.GetDescription(); // "男"
// 启用/禁用状态
var config = new SystemConfig { Status = ActiveStatus.Enabled };
var isDefault = YesNo.Yes; // 替代 bool 语义更清晰
// 位置信息
var location = new Coordinate(116.397128, 39.916527);
// 文件上传结果
var file = new FileItem("https://cdn.example.com/a.jpg", "photo.jpg", 102400, "image/jpeg");
// 时间范围查询入参
public class UserQuery : IHasSearchKey, IHasTimeRange
{
public string SearchKey { get; set; }
public DateTimeRange? TimeRange { get; set; }
}
// 字段长度约束
public class CreateUserDto
{
[MaxLength(MaxLenghtConst.L50)]
public string NickName { get; set; }
[MaxLength(MaxLenghtConst.L255)]
public string Bio { get; set; }
}
依赖
- Volo.Abp.Core — ABP 框架
- .NET 8 +
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Grace.Shared:
| Package | Downloads |
|---|---|
|
Grace.Core
基于abp常用核心、工具类的模块封装 |
|
|
Grace.TencentCloud
基于abp对腾讯云的模块封装 |
GitHub repositories
This package is not used by any popular GitHub repositories.