Mud.EntityCodeGenerator 1.1.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mud.EntityCodeGenerator --version 1.1.5
                    
NuGet\Install-Package Mud.EntityCodeGenerator -Version 1.1.5
                    
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="Mud.EntityCodeGenerator" Version="1.1.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mud.EntityCodeGenerator" Version="1.1.5" />
                    
Directory.Packages.props
<PackageReference Include="Mud.EntityCodeGenerator" />
                    
Project file
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 Mud.EntityCodeGenerator --version 1.1.5
                    
#r "nuget: Mud.EntityCodeGenerator, 1.1.5"
                    
#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 Mud.EntityCodeGenerator@1.1.5
                    
#: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=Mud.EntityCodeGenerator&version=1.1.5
                    
Install as a Cake Addin
#tool nuget:?package=Mud.EntityCodeGenerator&version=1.1.5
                    
Install as a Cake Tool

Mud 实体代码生成器

功能介绍

Mud 实体代码生成器是一个基于 Roslyn 的源代码生成器,用于根据实体类自动生成各种相关代码,提高开发效率。它包含以下主要功能:

  1. DTO代码生成 - 根据实体类自动生成数据传输对象(DTO)
  2. VO代码生成 - 根据实体类自动生成视图对象(VO)
  3. 查询输入类生成 - 根据实体类自动生成查询输入类(QueryInput)
  4. 创建输入类生成 - 根据实体类自动生成创建输入类(CrInput)
  5. 更新输入类生成 - 根据实体类自动生成更新输入类(UpInput)
  6. 实体映射方法生成 - 自动生成实体与DTO之间的映射方法

项目参数配置

在使用 Mud 实体代码生成器时,可以通过在项目文件中配置以下参数来自定义生成行为:

通用配置参数

<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>  
  <EntitySuffix>Entity</EntitySuffix>  
  <EntityAttachAttributes>SuppressSniffer</EntityAttachAttributes>  
</PropertyGroup>

<ItemGroup>
  <CompilerVisibleProperty Include="EntitySuffix" />
  <CompilerVisibleProperty Include="EntityAttachAttributes" />
</ItemGroup>

依赖项配置

<ItemGroup>
  
  <PackageReference Include="Mud.EntityCodeGenerator" Version="1.0.5" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
</ItemGroup>

配置参数说明

参数名 默认值 说明
EmitCompilerGeneratedFiles false 是否在obj目录下保存生成的代码,设为true便于调试
EntitySuffix Entity 实体类后缀,用于识别实体类
EntityAttachAttributes (空) 实体类上需要附加的特性,多个特性用逗号分隔

代码生成功能及样例

1. DTO/VO/输入类代码生成

在实体程序项目中添加生成器及配置相关参数:

<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  <EntitySuffix>Entity</EntitySuffix>
  <EntityAttachAttributes>SuppressSniffer</EntityAttachAttributes>
</PropertyGroup>
<ItemGroup>
  <CompilerVisibleProperty Include="EntitySuffix" />
  <CompilerVisibleProperty Include="EntityAttachAttributes"/>
</ItemGroup>

在实体中添加DtoGenerator特性:

/// <summary>
/// 客户端信息实体类
/// </summary>
[DtoGenerator]
[Table(Name = "sys_client"),SuppressSniffer]
public partial class SysClientEntity
{
    /// <summary>
    /// id
    /// </summary>
    [property: TableField(Fille = FieldFill.Insert, Value = FillValue.Id)]
    [property: Column(Name = "id", IsPrimary = true, Position = 1)]
    [property: Required(ErrorMessage = "id不能为空")]
    private long? _id;

    /// <summary>
    /// 客户端key
    /// </summary>
    [property: Column(Name = "client_key", Position = 3)]
    [property: Required(ErrorMessage = "客户端key不能为空")]
    [property: ExportProperty("客户端key")]
    private string _clientKey;

    /// <summary>
    /// 删除标志(0代表存在 2代表删除)
    /// </summary>
    [property: Column(Name = "del_flag", Position = 10)]
    [property: ExportProperty("删除标志")]
    [IgnoreQuery]
    private string _delFlag;
}

基于以上实体,将自动生成以下几类代码:

实体类属性
/// <summary>
/// 客户端信息实体类
/// </summary>
public partial class SysClientEntity
{
    /// <summary>
    /// id
    /// </summary>
    [TableField(Fille = FieldFill.Insert, Value = FillValue.Id), Column(Name = "id", IsPrimary = true, Position = 1)]
    public long? Id
    {
        get
        {
            return _id;
        }

        set
        {
            _id = value;
        }
    }

    /// <summary>
    /// 客户端key
    /// </summary>
    [Column(Name = "client_key", Position = 3)]
    public string? ClientKey
    {
        get
        {
            return _clientKey;
        }

        set
        {
            _clientKey = value;
        }
    }

    /// <summary>
    /// 删除标志(0代表存在 2代表删除)
    /// </summary>
    [Column(Name = "del_flag", Position = 10)]
    public string? DelFlag
    {
        get
        {
            return _delFlag;
        }

        set
        {
            _delFlag = value;
        }
    }

    /// <summary>
    /// 通用的实体映射至VO对象方法。
    /// </summary>
    public virtual SysClientListOutput MapTo()
    {
        var voObj = new SysClientListOutput();
        voObj.id = this.Id;
        voObj.clientKey = this.ClientKey;
        voObj.delFlag = this.DelFlag;
        return voObj;
    }
}
VO类 (视图对象)
/// <summary>
/// 客户端信息实体类
/// </summary>
[SuppressSniffer, CompilerGenerated]
public partial class SysClientListOutput
{
    /// <summary>
    /// id
    /// </summary>
    public long? id { get; set; }

    /// <summary>
    /// 客户端key
    /// </summary>
    [ExportProperty("客户端key")]
    public string? clientKey { get; set; }

    /// <summary>
    /// 删除标志(0代表存在 2代表删除)
    /// </summary>
    [ExportProperty("删除标志")]
    public string? delFlag { get; set; }
}
QueryInput类 (查询输入对象)
// SysClientQueryInput.g.cs
/// <summary>
/// 客户端信息实体类
/// </summary>
[SuppressSniffer, CompilerGenerated]
public partial class SysClientQueryInput : DataQueryInput
{
    /// <summary>
    /// id
    /// </summary>
    public long? id { get; set; }
    /// <summary>
    /// 客户端key
    /// </summary>
    public string? clientKey { get; set; }
    /// <summary>
    /// 删除标志(0代表存在 2代表删除)
    /// </summary>
    public string? delFlag { get; set; }

    /// <summary>
    /// 构建通用的查询条件。
    /// </summary>
    public Expression<Func<SysClientEntity, bool>> BuildQueryWhere()
    {
        var where = LinqExtensions.True<SysClientEntity>();
        where = where.AndIF(this.id != null, x => x.Id == this.id);
        where = where.AndIF(!string.IsNullOrEmpty(this.clientKey), x => x.ClientKey == this.clientKey);
        where = where.AndIF(!string.IsNullOrEmpty(this.delFlag), x => x.DelFlag == this.delFlag);
        return where;
    }
}
CrInput类 (创建输入对象)
// SysClientCrInput.g.cs
/// <summary>
/// 客户端信息实体类
/// </summary>
[SuppressSniffer, CompilerGenerated]
public partial class SysClientCrInput
{
    /// <summary>
    /// 客户端key
    /// </summary>
    [Required(ErrorMessage = "客户端key不能为空")]
    public string? clientKey { get; set; }
    /// <summary>
    /// 删除标志(0代表存在 2代表删除)
    /// </summary>
    public string? delFlag { get; set; }

    /// <summary>
    /// 通用的BO对象映射至实体方法。
    /// </summary>
    public virtual SysClientEntity MapTo()
    {
        var entity = new SysClientEntity();
        entity.ClientKey = this.clientKey;
        entity.DelFlag = this.delFlag;
        return entity;
    }
}
UpInput类 (更新输入对象)
/// <summary>
/// 客户端信息实体类
/// </summary>
[SuppressSniffer, CompilerGenerated]
public partial class SysClientUpInput : SysClientCrInput
{
    /// <summary>
    /// id
    /// </summary>
    [Required(ErrorMessage = "id不能为空")]
    public long? id { get; set; }

    /// <summary>
    /// 通用的BO对象映射至实体方法。
    /// </summary>
    public override SysClientEntity MapTo()
    {
        var entity = base.MapTo();
        entity.Id = this.id;
        return entity;
    }
}

3. 特性控制参数

DtoGenerator特性支持以下参数控制代码生成行为:

参数名 类型 默认值 说明
GenMapMethod bool true 是否生成实体映射方法
GenVoClass bool true 是否生成VO类
GenQueryInputClass bool true 是否生成查询输入类
GenBoClass bool true 是否生成BO类
DtoNamespace string "Dto" DTO类命名空间

使用示例:

[DtoGenerator(
    GenMapMethod = true,
    GenVoClass = true,
    GenQueryInputClass = false,
    DtoNamespace = "ViewModels"
)]
public class SysClientEntity : BaseEntity
{
    // 属性定义
}

维护者

倔强的泥巴

许可证

本项目采用MIT许可证模式:

免责声明

本项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。

不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任。

Product 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.2.3 64 11/6/2025
1.2.2 80 11/4/2025
1.2.1 165 10/31/2025
1.2.0 167 10/28/2025
1.1.9 167 10/15/2025
1.1.8 158 10/9/2025
1.1.7 97 10/4/2025
1.1.6 172 9/30/2025
1.1.5 180 9/29/2025
1.1.4 149 7/11/2025
1.1.3 248 12/31/2024 1.1.3 is deprecated because it is no longer maintained and has critical bugs.
1.1.2 230 12/30/2024 1.1.2 is deprecated because it is no longer maintained and has critical bugs.
1.1.1 223 12/30/2024 1.1.1 is deprecated because it is no longer maintained and has critical bugs.
1.1.0 223 12/29/2024 1.1.0 is deprecated because it is no longer maintained and has critical bugs.
1.0.9.4 224 12/28/2024 1.0.9.4 is deprecated because it is no longer maintained and has critical bugs.
1.0.9.3 231 12/28/2024 1.0.9.3 is deprecated because it is no longer maintained and has critical bugs.
1.0.9.1 228 12/26/2024 1.0.9.1 is deprecated because it is no longer maintained and has critical bugs.
1.0.9 231 12/26/2024 1.0.9 is deprecated because it is no longer maintained and has critical bugs.
1.0.8 234 12/25/2024 1.0.8 is deprecated because it is no longer maintained and has critical bugs.
1.0.7 230 12/25/2024 1.0.7 is deprecated because it is no longer maintained and has critical bugs.
1.0.6 231 12/25/2024 1.0.6 is deprecated because it is no longer maintained and has critical bugs.
1.0.5 238 12/25/2024 1.0.5 is deprecated because it is no longer maintained and has critical bugs.
1.0.4 227 12/25/2024 1.0.4 is deprecated because it is no longer maintained and has critical bugs.
1.0.3 240 12/25/2024 1.0.3 is deprecated because it is no longer maintained and has critical bugs.
1.0.2 237 12/25/2024 1.0.2 is deprecated because it is no longer maintained and has critical bugs.
1.0.1 232 12/25/2024 1.0.1 is deprecated because it is no longer maintained and has critical bugs.
0.3.1 232 12/26/2024 0.3.1 is deprecated because it is no longer maintained and has critical bugs.