cezarypiatek / MappingGeneratorIssueTracker

This is a issue tracker for MappingGenerator
2 stars 0 forks source link

create DTO class from method parameters #22

Open naji-makhoul opened 1 year ago

naji-makhoul commented 1 year ago

i have many functions in interface implemntaion, i want to create a webapi controler with one parameter as a dto class

there is a way to select multiple params from a function/method and convert it to new dto class ?

for example:

public async Task<List<students_QueryByDetailsResult>> SP_students_QueryByDetails(string PName, string Fname, string ParentPName, string ParentFname, double? student_id, double? parent_id, byte? Part, byte? @class, int? StudyYear, int? IncludeLeftStudents, int? UD_index1, int? UD_value1, int? UD_index2, int? UD_value2)
        {
            var result = await _context.Procedures.students_QueryByDetailsAsync(PName, Fname, ParentPName, ParentFname, student_id, parent_id, Part, @class, StudyYear, IncludeLeftStudents, UD_index1, UD_value1, UD_index2, UD_value2);
            return result;
        }

i want to copy all this params in function to new class like:

  public class ClassDTO
    {
        string PName { get; set; }
        string Fname { get; set; }
        string ParentPName { get; set; }
        string ParentFname { get; set; }
        double? student_id { get; set; }
        double? parent_id { get; set; }
        byte? Part { get; set; }
        byte? @class { get; set; }
        int? StudyYear { get; set; }
        int? IncludeLeftStudents { get; set; }
        int? UD_index1 { get; set; }
        int? UD_value1 { get; set; }
        int? UD_index2 { get; set; }
        int? UD_value2 { get; set; }
    }

im using efCore powertools to generate function to all my stored procedures from the database, and my SPs have alot of paramaters ... i looking to use it like a dto class from POST API

cezarypiatek commented 1 year ago

To automatically generate class properties based on the method parameters you need to 1) Create an empty target class (ClassDTO) 2) Set Unmapped sources toGenerate missing propertiesin theMatching` tab of MappingGenerator setts

MippingGenerator should automatically add missing properties matching method parameters

image

naji-makhoul commented 1 year ago

thank you , but i want to generate new dto class and it will replace all the parameters in the method ... it's not same returned class

somthing like:

public async Task<List<students_QueryByDetailsResult>> SP_students_QueryByDetails(**ClassDTO data**)
        {
            var result = await _context.Procedures.students_QueryByDetailsAsync(data.PName, data.Fname, data.ParentPName, data.ParentFname, data.student_id, data.parent_id, data.Part, data.@class, data.StudyYear, data.IncludeLeftStudents, data.UD_index1,data. UD_value1, data.data.UD_index2, data.UD_value2);
            return result;
        }
cezarypiatek commented 1 year ago

There's no such feature in MappingGenerator at the moment. I know, that this kind of refactoring is provided by Resharper and it's called "Transform Parameters"

image

image