royal-code / smartmapper Goto Github PK
View Code? Open in Web Editor NEWAn object-to-object mapper. Separated into four mapping categories: adapters, mappers, selectors, and specifiers.
License: GNU Affero General Public License v3.0
An object-to-object mapper. Separated into four mapping categories: adapters, mappers, selectors, and specifiers.
License: GNU Affero General Public License v3.0
Value Assignment Strategy será do tipo discovery.
A implementação terá as seguintes resoluções:
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).
Há dois tipos de mapeamento:
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();
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);
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);
Seguindo os diagrama do fluxo de adaptadores, deve ser criado todos os I...OptionsBuilder e suas implementações.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.