个人备案网站 内容,东莞海天网站建设,wordpress+推荐插件,网站的维护步骤代码生成项目参数配置在使用Mud代码生成器时#xff0c;可以通过在项目文件中配置以下参数来自定义生成行为#xff1a;开源项目Mud-Code-Generator 源代码Mud-Code-Generator 帮助文档通用配置参数PropertyGroupEmitCompilerGeneratedFilestrue/EmitCom…代码生成项目参数配置在使用Mud代码生成器时可以通过在项目文件中配置以下参数来自定义生成行为开源项目Mud-Code-Generator 源代码Mud-Code-Generator 帮助文档通用配置参数PropertyGroupEmitCompilerGeneratedFilestrue/EmitCompilerGeneratedFiles !-- 在obj目录下保存生成的代码 --EntitySuffixEntity/EntitySuffix !-- 实体类后缀配置 --EntityAttachAttributesSuppressSniffer/EntityAttachAttributes !-- 实体类加上Attribute特性配置多个特性时使用,分隔 --/PropertyGroupItemGroupCompilerVisibleProperty IncludeEntitySuffix /CompilerVisibleProperty IncludeEntityAttachAttributes //ItemGroup依赖项配置ItemGroup!-- 引入的代码生成器程序集注意后面的参数 --PackageReference IncludeMud.EntityCodeGenerator Version1.1.5 PrivateAssetsall OutputItemTypeAnalyzer ReferenceOutputAssemblyfalse//ItemGroup配置参数说明参数名 默认值 说明EmitCompilerGeneratedFiles false 是否在obj目录下保存生成的代码设为true便于调试EntitySuffix Entity 实体类后缀用于识别实体类EntityAttachAttributes (空) 实体类上需要附加的特性多个特性用逗号分隔代码生成功能及样例DTO/VO/输入类代码生成在实体程序项目中添加生成器及配置相关参数PropertyGroupEmitCompilerGeneratedFilestrue/EmitCompilerGeneratedFilesEntitySuffixEntity/EntitySuffixEntityAttachAttributesSuppressSniffer/EntityAttachAttributes/PropertyGroupItemGroupCompilerVisibleProperty IncludeEntitySuffix /CompilerVisibleProperty IncludeEntityAttachAttributes//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/// 客户端信息实体类/// /summarypublic 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对象方法。/// /summarypublic 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/// /summarypublic 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/// /summarypublic long? id { get; set; }/// summary/// 客户端key/// /summarypublic string? clientKey { get; set; }/// summary/// 删除标志0代表存在 2代表删除/// /summarypublic string? delFlag { get; set; }/// summary/// 构建通用的查询条件。/// /summarypublic ExpressionFuncSysClientEntity, bool BuildQueryWhere(){var where LinqExtensions.TrueSysClientEntity();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代表删除/// /summarypublic string? delFlag { get; set; }/// summary/// 通用的BO对象映射至实体方法。/// /summarypublic 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对象映射至实体方法。/// /summarypublic override SysClientEntity MapTo(){var entity base.MapTo();entity.Id this.id;return entity;}}特性控制参数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{// 属性定义}与传统代码生成器的比较相较于传统的代码生成器如CodeSmith和低代码平台的代码生成器Mud 代码生成器有着独特的优势零散添加字段不需要整体重新生成实体传统的代码生成器通常需要在模型变更时重新生成整个文件这可能导致已有的自定义代码丢失或者需要手动合并。而Mud代码生成器采用增量式生成方式在添加新字段时只需重新编译项目即可自动更新相关代码无需重新生成整个实体。零散添加字段不需要手动添加至其它DTO当实体新增字段时传统代码生成器往往需要手动将新字段添加到各个相关的DTO中容易遗漏且繁琐。Mud 代码生成器会在编译时自动检测实体变化并同步更新所有相关的DTO、VO以及各种输入类保证代码的一致性。代码整洁关注核心字段Mud 代码生成器遵循关注点分离原则将生成的代码与手写的业务逻辑完全隔离。开发者只需要关注核心业务字段的定义其他辅助代码会自动生成使代码更加整洁易维护。实时生成代码在编译时自动生成无需额外的操作步骤。开发者只需关注业务逻辑代码的编写当修改实体类并重新编译时所有相关的DTO、VO和输入类都会自动更新大大提升了开发效率。强类型安全基于Roslyn编译器平台提供强类型的代码生成和验证。生成的代码与项目中的其他代码一样都经过编译器的严格检查避免了运行时错误提高了代码质量和可靠性.高度可定制支持多种配置选项可以根据项目需求灵活调整生成规则。开发者可以通过项目配置文件控制生成行为如实体类后缀、需要附加的特性等满足不同项目的个性化需求。无缝集成作为.NET项目的一部分与现有开发流程完美融合。无需额外的工具或复杂的配置只需添加NuGet包引用并在项目中进行简单配置即可享受代码自动生成带来的便利。版本控制友好生成的代码不会污染版本历史便于团队协作。由于代码是在编译时生成的不会产生大量人工编写的重复代码使得版本控制系统中的变更记录更加清晰更容易进行代码审查和团队协作。使用方法在您的项目中添加对 Mud.EntityCodeGenerator 包的引用根据需要配置项目参数如实体后缀、特性等将实体类标记为 partial 并添加 [DtoGenerator] 特性