Giter Site home page Giter Site logo

royal-code / smartmapper Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 778 KB

An object-to-object mapper. Separated into four mapping categories: adapters, mappers, selectors, and specifiers.

License: GNU Affero General Public License v3.0

C# 100.00%
autofilter automapper autoselect

smartmapper's People

Contributors

eglauko avatar

Stargazers

 avatar

Watchers

 avatar  avatar

smartmapper's Issues

Value Assignment Strategy Resolver

Value Assignment Strategy será do tipo discovery.

A implementação terá as seguintes resoluções:

  • Direct
  • Cast (enum)
  • Cast (numbers/primitives)
  • Convert (Nullable/Default)
  • Adapt (Adapt+Map|Adapt|Map)

A estratégia Select terá de ser feita de manualmente, não fará parte do discovery.


Descrição antiga:

Implementar AssignmentStrategyResolver

Este será o primeiro resolver a ser concluído.

Após essa implementação será possível continuar a resolução de parâmetros do construtor, segundo para resolução do construtor e por fim do ativador (construtor escolhido).

Resolução do mapeamento de métodos.

Há dois tipos de mapeamento:

  • SourceToMethod
  • PropertyToMethod

Ao acionar no builder um ToMethod, deverá gerar ou obter uma ToMethodOptions existente.
Então os métodos ToMethod podem ter seletores, como o Delegate ou o nome + nº parametros ou tipos dos parâmetros.

Deve ser possível tratar o retorno do método, com uma função.

Deve-se poder criar tratamentos genéricos para retornos de função, pelo tipo retornado.
Quando não há nenhum tratamento para o retorno da função, o retorno é ignorado.
O tratamento deve retornar (void) (Action)

samples:

// maps the properties of the source type to the target method with name X.
builder.ToMethod("X");

// maps all source available properties to a target method.
builder.ToMethod();

// maps the given parameters to an unknown target method.
builder.ToMethod().Parameters(x => x.Name, x => x.Age);

// maps the properties of the source type to the target method with name X,
// where the two parameters of source type must be parameters of X.
// In this case, X method can have more parameters, but these two must be resolved.
builder.ToMethod("X")
    .Map(x => x.Name)
    .Map(x => x.Age);

// maps the source property to a target method, 
// where the inner properties will be mapped as parameters of the target method.
// In this case, the target type must hava a method with the property name, 
// and parameters with same names of the inner properties.
builder.Map(x => x.Something).ToMethod();

// maps the source property as a parameter (not defined) of a target method (not defined).
// In this case, the target type must have a single method with a single parameter of same type of the property type.
builder.Map(x => x.Name).ToMethod().ToParameter();

// maps multiples source properties to a method (Update) of a target property (SomeProp).
builder.Map(x => x.Name).To(t => t.SomeProp).ToMethod(p => p.Update).ToParameter();
builder.Map(x => x.Age).To(t => t.SomeProp).ToMethod(p => p.Update).ToParameter();

Resolução do mapeamento de construtores.

Samples:

// configure the constructor

// the target constructor must have two paramters
builder.Constructor().WithParameters(2);

// the target constructor must have a single parameter of type string
builder.Constructor().WithParameters(typeof(string));

// configure the target constructor parameters with the source properties
builder.Constructor().Parameters(x => x.Name, x => x.Age);

// configure the inner properties of a source property to be mapped to the constructor
builder.Map(x => x.SomeProp).ToConstructor();
// or
builder.Constructor().MapInnerProperties(x => x.SomeProp);

// configure a source property to be mapped to a parameter of the target constructor
builder.Map(x => x.Name).ToConstructor().ToParameter();
// or
builder.Constructor().Map(x => x.Name);

Ajustes no meio de mapeamento de construtores

Modificar este meio de mapear inner properties para um construtor:

builder.Map(s => s.Value).ToConstructor();

O problema se encontra em que o Map() retorna um mapeamento de propriedades, e isto impossibilita o reaproveitamento para mapeamentos Mapper, além do Adapter.

Poderia ser criado algums mapeamentos a nível de Construtor(), semelhante ao seguinte:

// map a property to a constructor parameter
builder.Constructor().MapParameter(s => s.Name);

// map inner properties to the constructor
builder.Constructor().Map(s => s.Value);

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.