zoukankan      html  css  js  c++  java
  • 使用AutoMapper 处理DTO数据对象的转换

    using AutoMapper;
    using System;

    namespace DTOtEST
    {
    class Program
    {
    static void Main(string[] args)
    {
    Student s = new Student();
    s.StuID = 123456;
    s.Name = "哈哈哈哈";
    s.Age = 20;

    var dd = new MapperConfiguration(cfg=>cfg.CreateMap<Student,StudentDTO>());
    StudentDTO ss = dd.CreateMapper().Map<StudentDTO>(s);
    Console.WriteLine(ss.Age);
    Console.WriteLine(ss.Name);
    Console.WriteLine(ss.StuID);
    Console.Read();
    }
    }

    //public class MyProfile : Profile
    //{
    // protected override void Configure()
    // {
    // CreateMap<Student, StudentDTO>();
    // CreateMap<Student, StudentDTO>().ForMember(dt => dt.Name, opt => opt.MapFrom(src => src.Name))
    // .ForMember(dt => dt.Age, opt => opt.MapFrom(src => src.Age));
    // }
    //}

    public class Student
    {
    private long stuID;
    public long StuID
    {
    get { return stuID; }
    set { stuID = value; }
    }

    private string name;
    public string Name
    {
    get { return name; }
    set { name = value; }
    }

    private int age;
    public int Age
    {
    get { return age; }
    set { age = value; }
    }

    private string address;

    public string Address
    {
    get { return address; }
    set { address = value; }
    }

    }

    public class StudentDTO
    {
    private long stuID;
    public long StuID
    {
    get { return stuID; }
    set { stuID = value; }
    }

    private string name;
    public string Name
    {
    get { return name; }
    set { name = value; }
    }

    private int age;
    public int Age
    {
    get { return age; }
    set { age = value; }
    }

    }
    }

  • 相关阅读:
    bootstrap模态框
    css 禁止选中文本
    Python Flask Tornado
    JS canvas标签动态绘制图型
    JS 跳转页面
    JS 计算器
    JS
    柱状图中最大的矩形
    在不使用第三个变量的情况下交换两个数的值
    springboot配置静态资源访问的2种方式
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/6642154.html
Copyright © 2011-2022 走看看