Shouldn't DeepCloning=false ignore Lists and collections?
#429
Replies: 3 comments 3 replies
-
By default Mapperly tries to avoid copying objects but when it has to (ie [Mapper]
public static partial class Mapper
{
public static partial B Map(A src);
// target.Value = global::System.Linq.Enumerable.ToList(src.Value);
// return target;
}
// With deep cloning
[Mapper(UseDeepCloning = true)]
public static partial class DeepMapper
{
public static partial B Map(A src);
// target.Value = global::System.Linq.Enumerable.ToList (global::System.Linq.Enumerable.Select(src.Value, x => MapToMyObject(x)));
// return target;
// private static global::Riok.Mapperly.Sample.MyObject MapToMyObject (global::Riok.Mapperly.Sample.MyObject source)
// {
// var target = new global::Riok.Mapperly.Sample.MyObject();
// target.Number = source.Number;
// target.Details = (int[])source.Details.Clone();
// return target;
// }
}
public class A
{
public MyObject[] Value { get; set; }
}
public class B
{
public List<MyObject> Value { get; set; }
}
public class MyObject
{
public int Number { get; set; }
public int[] Details { get; set; }
}
Do you have an example for this? Does this apply to classes like: |
Beta Was this translation helpful? Give feedback.
-
|
Your code example is irrelevant, If two object have get-only collection property, mapperly will iterate the collection: It will also do the same for nested collections too, resulting in a SH*TLOAD of code and there;'s no way to disable that, To repro try to map It will generate screens of stuff like this: What is it if not deep cloning. P.S. That's the reason my company froze the dependency at 2.6 and will never be upgrading, because there's no way to turn this off. |
Beta Was this translation helpful? Give feedback.
-
|
Any updates? How can I disable collection mapping completely? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The docs at https://mapperly.riok.app/docs/configuration/mapper explicitly say that if
DeepCloningis disabled and source/dest property cannot be simply assigned one to another - it won't be cloned. However with the new collection support in 2.7 and later it copies items one by one.P.S. Moreover, if a collection has some nested non-collection-related property - it is also copied. Like
dest.SomeCollection.Something = source.SomeCollection.SomethingI fell like this should either be ignored, of you should clarify the docs, precisely defining what "deep" means. ;) Thanks for a great project.
Beta Was this translation helpful? Give feedback.
All reactions