cezarypiatek / MappingGenerator

:arrows_counterclockwise: "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator
MIT License
1.03k stars 120 forks source link

Creating object in factory method #76

Closed rmaziarka closed 5 years ago

rmaziarka commented 5 years ago

Hello Cezary,

I tried to use your extension and found out that it lacks one functionality that I wanted to use.

From DTO / command class I want to create an entity. For example from CreateProductCommand I run ToProduct method.:

    public class CreateProductCommand
    {

        public string Name { get; set; }

        public decimal Price { get; set; }

        public Category Category { get; set; }

        public Tag[] Tags { get; set; }

        public Product ToProduct()
        {
            return new Product(); //<----
        }
    }

    public class Product
    {
        public Product(string name, decimal price, Category category, Tag[] tags)
        {
            Id = new Guid();
            Name = name;
            Price = price;
            Category = category;
            Tags = tags;
        }

        public Guid Id { get; private set; }

        public string Name { get; private set; }

        public decimal Price { get; private set; }

        public Category Category { get; private set; }

        public Tag[] Tags { get; private set; }
    }

Would be able to provide auto-generating data to this constructor? Or maybe where should I find such option in the extension to try to add it on my own.

cezarypiatek commented 5 years ago

Unfortunately this scenario is not currently supported but I think it looks easy to implement it. I will try to add this later.

cezarypiatek commented 5 years ago

Here's the version that contains an implementation of this feature https://ci.appveyor.com/api/buildjobs/pnh37mqxjxakl3ge/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix

@rmaziarka Would you mind to test it and let me know if everything is working as expected?

issue76

rmaziarka commented 5 years ago

Works great, thanks :)

cezarypiatek commented 5 years ago

An official version with this feature was released Please install version of the official channel https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator