Open jorisdebock opened 4 years ago
Right now it's impossible without huge redesign. Mappings for methods with signature Hello3 MapHello3(Hello hello)
are generated as a single expression. To achieve the same result as you propose a multi-statement output is required. This is on my TODO list but I can't promise if or when this will be implemented.
@cezarypiatek I can make a pull request of my code (wip), this already generates the above code without breaking any other tests.
cool, please do that, I will take a look at that
@cezarypiatek can you check if the following syntax works correctly? At least it doesn't give me any syntax errors:
public virtual Hello3 MapHello3(Hello hello)
{
return new GrpcService1.Hello3()
{
Message = hello.Message,
Names = {
hello.Names
}
};
}
UPDATE: I've tested it by myself and it's working. I think Mapping Generator should implement this syntax for collection without setters. I think there is a similar problem for other properties (complex object) without setters.
UPDATE: This kind of assignment is valid for types that implement IEnumerable
and contain a method void Add(IEnumerable<T> elements)
Could we add a mapping option for get only lists?
It is useful for when an object is doing the list initialization themself and only exposing a getter for the list. In my case, I am using protobuf/grpc which generates types with only a getter for the list. And filling the list should be done with Add/Addrange, it would be nice if the mapping for this can be generated.
e.g. the following objects
current generated result
would like to have the following code generated