CC.CodeGenerator.Attribute 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CC.CodeGenerator.Attribute --version 1.3.0
NuGet\Install-Package CC.CodeGenerator.Attribute -Version 1.3.0
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="CC.CodeGenerator.Attribute" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CC.CodeGenerator.Attribute --version 1.3.0
#r "nuget: CC.CodeGenerator.Attribute, 1.3.0"
#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.
// Install CC.CodeGenerator.Attribute as a Cake Addin
#addin nuget:?package=CC.CodeGenerator.Attribute&version=1.3.0

// Install CC.CodeGenerator.Attribute as a Cake Tool
#tool nuget:?package=CC.CodeGenerator.Attribute&version=1.3.0

CC.CodeGenerator

利用.Net的Source Generator功能,生成开发过程中哪些无聊的代码。

使用方法

1. 安装

安装代码生成包以及支持包

Install-Package CC.CodeGenerator
Install-Package CC.NetCore

因为VS的原因,在添加包引用或者升级包版本后,建议重启VS。

Program.cs中添加全局引用

global using CC.CodeGenerator;

2. 对象Mapping

创建Class或record文件,并加入Dto特性

Ignore:忽略不需要的属性

[Dto()]
public partial class PeopleEditDto
{
    public Guid PeopleId { get; set; }

    public string UserName { get; set; }

    public string City { get; set; }

    [Ignore]
    public string Display => $"{UserName} {City}";
}

效果演示

GIF 2022-1-21 13-44-18

3. 支持EF简化单表操作

Program.cs中加入EF实体引用

global using CC.CodeGenerator.Demo.Entity;

特性中增加参数

Context:上下文对象

Entity:映射的EF实体

[Dto(Context =nameof(DemoaContext),Entity =typeof(People))]
public partial class PeopleEditDto

查询和保存示例

var context=new DemoaContext();
var peoples= PeopleEditDto.SelectGen(context.People.Where(x => x.UserName.StartsWith("Latanya"))).ToList();

var me= peoples.FirstOrDefault();
me.City = "上海";
me.SaveGen(context);
context.SaveChanges();

3. 服务注册代码自动创建

Program.cs中标记注册位置

var builder = WebApplication.CreateBuilder(args);

CC.CodeGenerator.AutoDI.AddServices(builder);//加入此行代码

服务中增加ServiceAttribute

LifeCycle:自定义生命周期,默认Scoped

[Service(LifeCycle = ELifeCycle.Singleton)]
public class WeatherForecastService

4. 自动实现INotifyPropertyChanged接口

[AddNotifyPropertyChanged]
internal partial class Demo
{
    public int MyProperty { get => _MyProperty; set => SetProperty(ref _MyProperty, value); }
    private int _MyProperty;

}
var data = new Demo();
data.PropertyChanged += (s, e) => Console.WriteLine($"属性{e.PropertyName}被修改");
data.MyProperty = 1;
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. 
.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 (1)

Showing the top 1 NuGet packages that depend on CC.CodeGenerator.Attribute:

Package Downloads
CC.CodeGenerator

常见简单业务的代码自动生成,解放劳动力。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2023.4.325 387 3/25/2023
2023.3.304 321 3/4/2023
1.9.1.725 731 7/25/2022
1.9.0.723 613 7/23/2022
1.8.4.721 633 7/21/2022
1.8.3.719 632 7/19/2022
1.8.2.716 383 7/16/2022
1.8.1.709 936 7/9/2022
1.8.0.709 651 7/9/2022
1.7.0.617 644 6/17/2022
1.6.1.616 643 6/16/2022
1.6.0.508 656 5/8/2022
1.3.0 1,095 3/19/2022