Biwen.AutoClassGen by vipwan
Nuget / site data
Details
Info
info
Name: Biwen.AutoClassGen
Biwen.AutoClassGen, CodeGEN
Author: vipwan
NuGet: https://www.nuget.org/packages/Biwen.AutoClassGen/
You can find more details at https://github.com/vipwan/Biwen.AutoClassGen
Original Readme
note
Biwen.AutoClassGen
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
Usage
dotnet add package Biwen.AutoClassGen.Attributes
Used by
if you use this library, please tell me, I will add your project here.
About
note
Generating properties from interface to class.
How to use
Example ( source csproj, source files )
- CSharp Project
- Program.cs
- Person.cs
- IPerson.cs
- IPerson2.cs
This is the CSharp Project that references Biwen.AutoClassGen
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Biwen.AutoClassGen" Version="1.0.0.6" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="Biwen.AutoClassGen.Attributes" Version="1.0.0" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
This is the use of Biwen.AutoClassGen in Program.cs
using FromInterface;
Console.WriteLine("Hello, World!");
Person p = new();
p.FirstName = "Andrei";
p.LastName = "Ignat";
Console.WriteLine(p.FullName());
This is the use of Biwen.AutoClassGen in Person.cs
namespace FromInterface;
public partial class Person //: IPerson
{
public string FullName() { return FirstName + " " + LastName; }
}
This is the use of Biwen.AutoClassGen in IPerson.cs
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace FromInterface;
public interface IPerson
{
[StringLength(100), Description("person first name")]
string FirstName { get; set; }
string LastName { get; set; }
public string FullName();
}
This is the use of Biwen.AutoClassGen in IPerson2.cs
using Biwen.AutoClassGen.Attributes;
namespace FromInterface;
[AutoGen("Person", "FromInterface")]
public interface IPerson2: IPerson
{
}
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- Biwen.AutoClassGen.Person.IPerson2.g.cs
// <auto-generated />
// author:vipwan@outlook.com 万雅虎
// issue:https://github.com/vipwan/Biwen.AutoClassGen/issues
// 如果你在使用中遇到问题,请第一时间issue,谢谢!
// This file is generated by Biwen.AutoClassGen.SourceGenerator
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FromInterface;
#pragma warning disable
namespace FromInterface
{
public partial class Person : IPerson2
{
/// <inheritdoc cref = "IPerson.FirstName"/>
[System.ComponentModel.DataAnnotations.StringLengthAttribute(100)]
[System.ComponentModel.DescriptionAttribute("person first name")]
public string FirstName { get; set; }
/// <inheritdoc cref = "IPerson.LastName"/>
public string LastName { get; set; }
}
}
#pragma warning restore
Usefull
Download Example (.NET C# )
Share Biwen.AutoClassGen
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Biwen.AutoClassGen