Skip to content

Latest commit

 

History

History
125 lines (111 loc) · 2.96 KB

Gen-Dto.md

File metadata and controls

125 lines (111 loc) · 2.96 KB

Usage

Your Entitys

namespace Biwen.AutoClassGen.TestConsole.Entitys
{
    public class User : Info
    {
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; } = null!;
        /// <summary>
        /// first name
        /// </summary>
        public string FirstName { get; set; } = null!;
        /// <summary>
        /// last name
        /// </summary>
        public string LastName { get; set; } = null!;
        /// <summary>
        /// age
        /// </summary>
        public int? Age { get; set; }
        /// <summary>
        /// fullname
        /// </summary>
        public string? FullName => $"{FirstName} {LastName}";
    }
    public abstract class Info : Other
    {
        /// <summary>
        /// email
        /// </summary>
        public string? Email { get; set; }
    }
    public abstract class Other
    {
        /// <summary>
        /// remark
        /// </summary>
        public string? Remark { get; set; }
    }
}

Define Dto Partial Class & mark AutoDtoAttribute

using Biwen.AutoClassGen.TestConsole.Entitys;
namespace Biwen.AutoClassGen.TestConsole.Dtos
{
    [AutoDto(typeof(User), nameof(User.Id), "TestCol")]
    public partial class UserDto
    {
    }
}

Enjoy

// <auto-generated />
// author:[email protected] 万雅虎
// 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 Biwen.AutoClassGen.TestConsole.Entitys;

#pragma warning disable
namespace Biwen.AutoClassGen.TestConsole.Dtos
{
    public partial class UserDto
    {
        /// <inheritdoc cref = "User.FirstName"/>
        public string FirstName { get; set; }
        /// <inheritdoc cref = "User.LastName"/>
        public string LastName { get; set; }
        /// <inheritdoc cref = "User.Age"/>
        public int? Age { get; set; }
        /// <inheritdoc cref = "User.FullName"/>
        public string? FullName { get; set; }
        /// <inheritdoc cref = "Info.Email"/>
        public string? Email { get; set; }
        /// <inheritdoc cref = "Other.Remark"/>
        public string? Remark { get; set; }
    }
}

namespace Biwen.AutoClassGen.TestConsole.Entitys
{
    using Biwen.AutoClassGen.TestConsole.Dtos;
    public static partial class UserToUserDtoExtentions
    {
        /// <summary>
        /// mapper to UserDto
        /// </summary>
        /// <returns></returns>
        public static UserDto MapperToDto(this User model)
        {
            return new UserDto()
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Age = model.Age,
                FullName = model.FullName,
                Email = model.Email,
                Remark = model.Remark,
            };
        }
    }
}
#pragma warning restore