Uh oh!
There was an error while loading. Please reload this page.
Fix issue #755 - Regression in interfaces mapping introduced by #649 - #756
Conversation
andrerav
commented
Jan 7, 2025
@DocSvartz Please take a look and let me know if this looks okay to you. I can make a speedy release this afternoon :) |
DocSvartz
commented
Jan 7, 2025
@lofcz Please Do not Close Issue. |
@DocSvartz could you elaborate? I find it strange that if we add any props to the interface: [TestMethod]publicvoidMappingToInterface_VerifyReadonlyPropsInterfaceAnyPropRule(){SampleInterfaceClsWithPropsource=newSampleInterfaceClsWithProp{ActivityData=newSampleActivityDataWithProp{Data=newSampleActivityParsedData{Steps=newList<string>{"A","B","C"}}}};SampleInterfaceClsWithProptarget=source.Adapt<SampleInterfaceClsWithProp>();target.ShouldNotBeNull();target.ShouldSatisfyAllConditions(()=>target.ActivityData.ShouldBe(source.ActivityData));}publicinterfaceIActivityDataWithProp{intTest{get;set;}}publicclassSampleInterfaceClsWithProp{publicIActivityDataWithProp?ActivityData{get;set;}publicSampleInterfaceClsWithProp(){}publicSampleInterfaceClsWithProp(IActivityDataWithPropdata){SetActivityData(data);}publicvoidSetActivityData(IActivityDataWithPropdata){ActivityData=data;}}publicclassSampleActivityDataWithProp:IActivityDataWithProp{publicintTest{get;set;}=42;publicSampleActivityParsedDataData{get;set;}}publicclassSampleActivityParsedData{publicList<string>Steps{get;set;}=newList<string>();}When mapping with default config we run into: // BaseAdapter.cs://if mapping to interface, create dynamic type implementing itelseif(arg.DestinationType.GetTypeInfo().IsInterface){
...And we synthesize a new type implementing just |
DocSvartz
commented
Jan 7, 2025
As far as I understand, this is done in order to create an instance class that can be filled with values from the source. |
lofcz
commented
Jan 7, 2025
That's right but wouldn't it be better to do something like https://github.com/lofcz/DeepCloner/blob/9abf692a58da2e76b4dac6a266f45fbd573dc621/DeepCloner.Core/Helpers/DeepClonerExprGenerator.cs instead? The current behavior is unintuitive and I can't think of a scenario where one would intentionally want to do this. Synthesizing a new type also means methods are lost. |
DocSvartz
commented
Jan 7, 2025
If you are talking about the Update scenario:
Yes, This should not happen. And in the Create scenario:
You can't know which implementation will be chosen anyway |
Yes, I mean "updating" specifically (cloning an existing object into another existing object). |
But "updating" happens exactly as you want. I think, you want the "Creating" scenario to copy the Implementing "interface Source" Type to the Destination? But it seems that this will only work if they match. As in your example. |
That's what I mean Hm, There is another option though. |
DocSvartz
commented
Jan 8, 2025
I even managed to make this option work. )) |
lofcz
commented
Jan 8, 2025
Looks great to me. |
DocSvartz
commented
Jan 8, 2025
andrerav
commented
Jan 13, 2025
Thank you @lofcz and @DocSvartz! |
Fixes#755, @andrerav could you please take a look and potentially release a new pre-release version? This regression could've affected many customers (it did us at least) - but the pattern is common.
@DocSvartz CC, I want to verify this doesn't break your code (tests are passing).