Biwen.AutoClassGen
1.8.6
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Biwen.AutoClassGen --version 1.8.6
NuGet\Install-Package Biwen.AutoClassGen -Version 1.8.6
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="Biwen.AutoClassGen" Version="1.8.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Biwen.AutoClassGen" Version="1.8.6" />
<PackageReference Include="Biwen.AutoClassGen" />
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 Biwen.AutoClassGen --version 1.8.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Biwen.AutoClassGen, 1.8.6"
#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 Biwen.AutoClassGen@1.8.6
#: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=Biwen.AutoClassGen&version=1.8.6
#tool nuget:?package=Biwen.AutoClassGen&version=1.8.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Biwen.AutoClassGen
Biwen.AutoClassGen 是一个代码生成工具库,通过源代码生成器(Source Generator)技术自动创建常用代码模式,简化开发流程,提高工作效率。
主要功能
- DTO自动生成:自动从实体类生成DTO对象,并创建映射扩展方法
- 请求对象生成:快速生成具有相同字段的请求对象族,减少重复工作
- AOP装饰器模式:自动实现装饰器模式,无需手动编写大量样板代码
- 依赖注入自动注册:通过简单的特性标记,自动注册服务到DI容器
- 版本信息生成:自动生成程序集版本信息
- 元数据生成:自动生成程序集元数据
- 代码分析与修复:提供多种代码分析规则和自动修复功能
- 枚举描述生成:根据枚举值自动生成描述信息(
Description,Display),方便在UI中显示
快速开始
安装
<ItemGroup>
<PackageReference Include="Biwen.AutoClassGen.Attributes" Version="x.x.x" />
<PackageReference Include="Biwen.AutoClassGen" Version="x.x.x" PrivateAssets="all" />
</ItemGroup>
主要功能示例
1. DTO自动生成
通过简单的特性标记,自动生成DTO类和映射方法:
[AutoDto(typeof(User))] // 或使用 C# 11+ 的泛型特性: [AutoDto<User>]
public partial class UserDto
{
// 属性会自动从User类生成
}
2. 装饰器模式自动实现
轻松实现AOP装饰器模式:
[AutoDecor<LoggingDecorator>]
public interface IUserService
{
Task<User> GetUserAsync(int id);
}
3. 依赖注入自动注册
自动注册服务到DI容器:
[AutoInject<IUserService>(ServiceLifetime.Scoped)]
public class UserService : IUserService
{
// 实现代码
}
4. 版本信息自动生成
自动生成程序集版本信息,支持git版本号:
Console.WriteLine($"Version: {XXX.Generated.Version}");
Console.WriteLine($"Version: {XXX.Generated.AssemblyMetadata}");
5. 枚举描述自动生成
[AutoDescription]
public enum UserStatus
{
[Description("正常")]
Normal,
[Description("禁用")]
Disabled,
[Display(Name = "已删除")]
Deleted
}
// 生成的描述信息
Console.WriteLine(UserStatus.Normal.Description()); // 输出: 正常
Console.WriteLine(UserStatus.Deleted.Description()); // 输出: 已删除
详细文档
以下是每个功能的详细使用说明:
代码分析器功能
该库提供了一系列代码分析器,帮助您编写更规范、更高质量的代码:
生成器相关规则
GEN001: 检查接口继承关系,确保能正确生成实现类GEN011: 防止生成类与接口名称冲突GEN021: 建议使用统一的命名空间以提高代码组织性GEN031: 提示使用[AutoGen]特性实现自动生成
DTO生成器规则
GEN041: 检测重复的[AutoDto]特性标注GEN042: 禁止在抽象类上使用[AutoDto]特性GEN044:[AutoDto]无法解析目标类型,请确保引用了正确的程序集并且类型可访问GEN045: 确保标记[AutoDto]的类声明为 partial
装饰器相关规则
GEN043: 确保被[AutoDecor]标记的类型具有public访问级别
代码风格规则
GEN050: 检查文件是否包含必要的头部注释信息GEN051: 确保异步方法名称以Async结尾GEN052: 推荐使用C# 10的文件作用域命名空间声明GEN053: 确保源代码文件使用UTF-8编码
自动代码修复
本库提供多个自动代码修复功能,帮助您快速修正代码问题:
- ✨ 自动添加缺失的文件头部注释
- 🔄 将异步方法名称规范化(添加Async后缀)
- 🎯 自动应用
[AutoGen]特性 - 🔍 移除重复的特性标注
- 📝 转换为文件作用域命名空间
- 🛠 更多代码修复持续添加中...
使用该库的项目
以下是一些使用Biwen.AutoClassGen的优秀项目:
- Biwen.QuickApi - 快速API开发框架
如果您的项目正在使用本库,欢迎通过PR将您的项目添加到此列表!
参与贡献
欢迎提交Pull Request来改进这个项目!无论是修复bug、添加新功能,还是完善文档,我们都非常感谢您的贡献。
开源协议
本项目采用MIT协议开源,详见 LICENSE 文件。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.8.7 | 203 | 10/12/2025 |
| 1.8.6 | 178 | 9/28/2025 |
| 1.8.5.1 | 279 | 9/15/2025 |
| 1.8.1 | 253 | 4/18/2025 |
| 1.8.0 | 474 | 4/18/2025 |
| 1.7.0 | 252 | 4/8/2025 |
| 1.6.0 | 228 | 4/3/2025 |
| 1.5.6 | 215 | 3/19/2025 |
| 1.5.5 | 218 | 2/18/2025 |
| 1.5.4 | 198 | 11/27/2024 |
| 1.5.3 | 234 | 11/12/2024 |
| 1.5.2 | 170 | 11/8/2024 |
| 1.5.1.3 | 211 | 9/26/2024 |
| 1.5.0 | 197 | 9/18/2024 |
Loading failed
提供对复杂类型的DTO生成支持