Coder Social home page Coder Social logo

mapto's People

Contributors

mrtaikandi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mapto's Issues

Use full type name in generated code.

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 ๐Ÿ‘

Special cases

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:

Support mapping from methods

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)]

add partial

For more flexibility, add a

partial void AfterCopy( original)

and call in the constructor to let the people to add their implementation

ReverseMap() capability

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?

Build fails without <MapTo_ConstructorAccessModifier> set

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>

Method-based conversion

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}";
    */
}

'NotNullIfNotNullAttribute' is inaccessible due to its protection level

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.

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.