mrtaikandi / mapto Goto Github PK
View Code? Open in Web Editor NEWA convention based object to object mapper using Roslyn source generator.
License: MIT License
A convention based object to object mapper using Roslyn source generator.
License: MIT License
Is there support for IQueryable projections?
For more flexibility, add a
partial void AfterCopy( original)
and call in the constructor to let the people to add their implementation
Without setting this property my build fails with this error:
'' is not a valid value for MapTo_ConstructorAccessModifier property.
Seems like it's just missing a default value in case it's null or blank. Workaround is to just add the property into the referencing project:
<PropertyGroup>
<MapTo_ConstructorAccessModifier>Internal</MapTo_ConstructorAccessModifier>
</PropertyGroup>
On some project I have to use quite specific API which exposes models with methods instead of properties.
For example, API model:
class Entity
{
int EntityId() {...}
}
My model:
[MapFrom(typeof(Entity)]
partial class EntityDTO
{
int EntityId { get; }
}
But, obviously, it doesn't work. What do you think about adding this? Would you accept such a PR?
If you think it is a rare case, could you consider optional support? We could add some kind of configuration like [MapFrom(typeof(Entity), MapMethods = true)]
The error message above is produced when I use this generator within a .NET Framework project with LangVersion=latest.
Setting SupportNullableStaticAnalysis to false in SourceGenerationOptions works for me.
C#9 is technically not fully supported for .NET Framework, but it works and we are using it for all projects. The supportNullableStaticAnalysis would need another check than just CSharp version.
Hello!!
Very cool library! I love the converter ability!!
Questions
1.) Are there any plans to release a major release beyond Pre-release
?
2.) Is there a to-do list or roadmap that we can help with?
Thanks!
Hi , I was using automapper to map my DTO with my Entity in my project, bumped into this and decided to give it a try. Normally once i defined my DTO i can use .ReverseMap() to handle the reverse mapping case as state here https://docs.automapper.org/en/stable/Reverse-Mapping-and-Unflattening.html
using back the example in README
var user = new User(id: 10) { FirstName = "John", LastName = "Doe" };
var vm = user.ToUserViewModel(); // A generated extension method for User class.
var newUser = User.fromViewModel(vm)
is that possible to be done?
It would be awesome if there is a chance to customize mapping method body with some lambda expression.
In example
// Source
public class OrderLine
{
public int Amount { get; set; }
public float UnitPrice { get; set; }
}
// Target
[MapFrom(typeof(OrderLine))]
public class OrderLineViewModel
{
[MapProperty(Rule = "Amount * UnitPrice")] // ๐ Something like this
public float TotalPrice { get; set; }
}
And some class to define customizations:
Currently you have to implement ITypeConverter in order to provide a conversion for types that cannot be implicitly casted. I find it slightly complicated. What if we allow converting based on methods? Something like this:
[MapFrom(typeof(User))]
public partial class UserViewModel
{
public DateTimeOffset RegisteredAt { get; set; }
[IgnoreProperty]
public ProfileViewModel Profile { get; set; }
[MapTypeConverter(nameof(ConvertKey))]
[MapProperty(SourcePropertyName = nameof(User.Id))]
public string Key { get; }
public static string ConvertKey(int source, object[] converterParameters) => $"{source:X}";
/* This should be also allowed. If you don't set the parameter, you don't have to add it to the contract
public static string ConvertKey(int source) => $"{source:X}";
*/
}
If you got same name for class and namespace. it not work.
for exemple
public global::Sale.Sale Sale {
get { return sale_; }
set {
sale_ = value;
}
}
cannot be mapped with this generated code
public static SaleModel ToSaleModel(this Sale sale)
{
return sale == null ? null : new SaleModel(sale);
}
Should be something like
public static SaleModel ToSaleModel(this global::Sale.Sale sale)
{
return sale == null ? null : new SaleModel(sale);
}
Thank for you work ๐
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.