diff --git a/README-zh.md b/README-zh.md index 21e9753..771dbf2 100644 --- a/README-zh.md +++ b/README-zh.md @@ -6,153 +6,14 @@ ### 用法 -#### 1.在Interface中定义属性 - -```c# - /// - /// 分页 - /// - public interface IPager - { - /// - /// 页码 - /// - [DefaultValue(0), Description("页码,从0开始")] - [Range(0, int.MaxValue)] - int? CurrentPage { get; set; } - /// - /// 分页项数 - /// - [DefaultValue(10), Description("每页项数,10-30之间")] - [Range(10, 30)] - int? PageLen { get; set; } - } - /// - /// 查询 - /// - public interface IQuery - { - /// - /// 关键字 - /// - [StringLength(100), Description("查询关键字")] - string? KeyWord { get; set; } - } - /// - /// 多租户请求 - /// - public interface ITenantRequest - { - /// - /// 租户ID - /// - [Required, Description("租户ID"), DefaultValue("default")] - [FromHeader(Name = "tenant-id")] - string? TenantId { get; set; } - } -``` -#### 2.标注需要生成的类 - -```c# - - //支持多次标注,可以生成多个类 - [AutoGen("QueryRequest", "Biwen.AutoClassGen.Models")] - [AutoGen("Query2Request", "Biwen.AutoClassGen.Models")] - public interface IQueryRequest : IPager, IQuery - { - } - - /// - /// 多租户请求 - /// - [AutoGen("MyTenantRequest", "Biwen.AutoClassGen.Models")] - public interface ITenantRealRequest : ITenantRequest - { - } - - //如果接口中有方法,需要定义一个partial类,实现接口中的方法 - //如果接口中没有方法,可以不定义partial类 - //当然partial类很重要,一般含有业务逻辑 根据需要自行决定 - public partial class QueryRequest - { - public string TestMethod(string arg1, int arg2) - { - return $"{arg1} {arg2}"; - } - } -``` -#### 3.Gen自动生成类 - -```c# - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Text; -using System.Threading.Tasks; -using Biwen.AutoClassGen.TestConsole.Interfaces; - -#pragma warning disable -namespace Biwen.AutoClassGen.Models -{ - public partial class QueryRequest : IQueryRequest - { - /// - [System.ComponentModel.DefaultValueAttribute(0)] - [System.ComponentModel.DescriptionAttribute("页码,从0开始")] - [System.ComponentModel.DataAnnotations.RangeAttribute(0, 2147483647)] - public int? CurrentPage { get; set; } - - /// - [System.ComponentModel.DefaultValueAttribute(10)] - [System.ComponentModel.DescriptionAttribute("每页项数,10-30之间")] - [System.ComponentModel.DataAnnotations.RangeAttribute(10, 30)] - public int? PageLen { get; set; } - - /// - [System.ComponentModel.DataAnnotations.StringLengthAttribute(100)] - [System.ComponentModel.DescriptionAttribute("查询关键字")] - public string? KeyWord { get; set; } - } - - public partial class Query2Request : IQueryRequest - { - /// - [System.ComponentModel.DefaultValueAttribute(0)] - [System.ComponentModel.DescriptionAttribute("页码,从0开始")] - [System.ComponentModel.DataAnnotations.RangeAttribute(0, 2147483647)] - public int? CurrentPage { get; set; } - - /// - [System.ComponentModel.DefaultValueAttribute(10)] - [System.ComponentModel.DescriptionAttribute("每页项数,10-30之间")] - [System.ComponentModel.DataAnnotations.RangeAttribute(10, 30)] - public int? PageLen { get; set; } - - /// - [System.ComponentModel.DataAnnotations.StringLengthAttribute(100)] - [System.ComponentModel.DescriptionAttribute("查询关键字")] - public string? KeyWord { get; set; } - } - - public partial class MyTenantRequest : ITenantRealRequest - { - /// - [System.ComponentModel.DataAnnotations.RequiredAttribute] - [System.ComponentModel.DescriptionAttribute("租户ID")] - [System.ComponentModel.DefaultValueAttribute("default")] - [Microsoft.AspNetCore.Mvc.FromHeaderAttribute(Name = "tenant-id")] - public string? TenantId { get; set; } - } -} -#pragma warning restore - +```bash +dotnet add package Biwen.AutoClassGen.Attributes ``` -### 错误码 +- [DTO生成器文档](https://github.com/vipwan/Biwen.AutoClassGen/blob/master/Gen-Dto.md) +- [Req生成器文档](https://github.com/vipwan/Biwen.AutoClassGen/blob/master/Gen-request.md) +- [Decor装饰器文档](https://github.com/vipwan/Biwen.AutoClassGen/blob/master/Gen-Decor.md) -- GEN001: 标注特性[AutoGen]的接口必须继承至少一个接口 -- GEN011: 非法的类命名 -- GEN021: 警告没有使用相同的命名空间 -- GEN031: 建议标注特性[AutoGen]以便生成类 +### Used by +#### if you use this library, please tell me, I will add your project here. +- [Biwen.QuickApi](https://github.com/vipwan/Biwen.QuickApi) diff --git a/README.md b/README.md index eb3cff9..6b97d3d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ # Biwen.AutoClassGen -Usage scenario: In many cases, we will have a lot of request objects, +#### Usage scenario + +- In many cases, we will have a lot of request objects, such as GetIdRequest, GetUserRequest, etc..., and these requests may have a large number of the same fields. For example, the multi-tenant Id, the number of pages, and these attribute fields may have validation rules, binding rules, and Swagger descriptions. If all this code needs to be written, it will add a lot of work, so Biwen.AutoClassGen came into being to solve this pain point... +- In many cases, we will have a lot of DTO objects, +- AOP & Decorator + + [中文](https://github.com/vipwan/Biwen.AutoClassGen/blob/master/README-zh.md)