Giter Club home page Giter Club logo

rey.mapping's Introduction

Rey.Mapping

灵活的dotnet core映射库,主要为了解决AutoMapper在使用过程中不够灵活的问题。

使用

基本

public class PersonFrom {
    public string Name { get; set; }
    public PersonFrom Parent { get; set; }
    public List<PersonFrom> Children { get; set; }
}

public class PersonTo {
    public string Name { get; set; }
    public PersonTo Parent { get; set; }
    public PersonTo[] Children { get; set; }
}

static void Main(string[] args) {
  var mapper = new MapperBuilder().Build();
  var from = new PersonFrom() {
      Name = "Person",
      Parent = new PersonFrom { Name = "Parent" },
      Children = new List<PersonFrom> {
          new PersonFrom{ Name = "Child 1" },
          new PersonFrom{ Name = "Child 2" }
      },
  };

  var to = mapper.From(from).To<PersonTo>();
}

忽略字段

从源对象上忽略字段

var to = mapper.From(from, opts => opts.Ignore(x => x.Name)).To<PersonTo>();

从目标对象上忽略字段

var to = mapper.From(from).To<PersonTo>(opts => opts.Ignore(x => x.Name));

字段映射

从源对象上映射

var to = mapper.From(from, opts => opts.Map(x => x.Name, "Parent.Name")).To<PersonTo>();

从目标对象上映射

var to = mapper.From(from).To<PersonTo>(opts => opts.Map(x => x.Name, x => x.Parent.Name));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.