Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MapDerivedType for existing target type mapping #918

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

TimothyMakkison
Copy link
Collaborator

@TimothyMakkison TimothyMakkison commented Nov 19, 2023

feat: partially add MapDerivedType for existing target type mapping

Description

Partially add MapDerivedType for void mapping methods. Doesn't support object (runtimeTargetTypeMapping???) or generic mapping, I'll do it in a separate PR.

  • Need to update docs, exception and xml comments.
  • Haven't added tests.
  • Not sure if my indetation is correct.
  • User defined void mappings should be added in a different PR.

Example generated code

public partial void Map(global::A src, global::B trg)
{
    switch (src, trg)
    {
        case (global::AImpl1 source, global::BImpl1 target):
            target.BaseValue = source.BaseValue;
            target.Value1 = source.Value1;
            break;
        case (global::AImpl2 source, global::BImpl2 target):
            target.BaseValue = source.BaseValue;
            target.Value2 = source.Value2;
            break;
        default:
            throw new System.ArgumentException($"Cannot map {src.GetType()} to B as there is no known derived type mapping", nameof(src));
    }
}

Fixes #694

Checklist

  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

Copy link

codecov bot commented Nov 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7628cf3) 91.29% compared to head (da6c1ff) 91.38%.
Report is 1 commits behind head on main.

❗ Current head da6c1ff differs from pull request most recent head ba720dc. Consider uploading reports for the commit ba720dc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #918      +/-   ##
==========================================
+ Coverage   91.29%   91.38%   +0.08%     
==========================================
  Files         222      223       +1     
  Lines        7165     7239      +74     
  Branches      907      909       +2     
==========================================
+ Hits         6541     6615      +74     
  Misses        412      412              
  Partials      212      212              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TimothyMakkison
Copy link
Collaborator Author

TimothyMakkison commented Nov 19, 2023

I intentionally kept bool duplicatedSourceTypesAllowed to make it easier to add generic and runtime mapping (assuming the logic carries over).

@TimothyMakkison TimothyMakkison force-pushed the existing_map_derive branch 4 times, most recently from 11dec6b to 0424be5 Compare November 20, 2023 20:09
Copy link
Contributor

@latonz latonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR! 😊 I added my feedback 😊

@TimothyMakkison TimothyMakkison force-pushed the existing_map_derive branch 4 times, most recently from 9673fbb to 8af73a1 Compare November 23, 2023 18:19
@TimothyMakkison
Copy link
Collaborator Author

Thanks for the review 👍 I think I've made your changes, really liked the simplification of DerivedTypeMappingBuilder.

Opted to not create SwitchDefaultSection although I can add it if you want.

Copy link
Contributor

@latonz latonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates, looks almost ready to merge, few smaller things I noted.
Also an integration test should be added and the documentation should be updated (as you already noted in the PR description ToDo-List 😊 )

@TimothyMakkison
Copy link
Collaborator Author

Can't (easily) do the integration tests rn because of a weird bug - can't find the correct file in the debug artifacts folder.

Which docs section should I update?

@latonz
Copy link
Contributor

latonz commented Nov 25, 2023

Can't (easily) do the integration tests rn because of a weird bug - can't find the correct file in the debug artifacts folder.

Can you elaborate on the bug? Probably run dotnet clean; dotnet build. Note: we recently switched to the simplified .NET 8.0 artifacts output: #917

Which docs section should I update?

I'd add a sentence in derived-type-mapping.md that derived type mappings are also supported for existing target object mappings with a reference to the existing target object mapping page.

@TimothyMakkison TimothyMakkison force-pushed the existing_map_derive branch 3 times, most recently from 02418ec to 2e5e8fa Compare November 29, 2023 13:25
@TimothyMakkison TimothyMakkison marked this pull request as draft November 29, 2023 15:23
@TimothyMakkison TimothyMakkison force-pushed the existing_map_derive branch 3 times, most recently from b536683 to b2d8031 Compare November 29, 2023 21:00
@TimothyMakkison TimothyMakkison marked this pull request as ready for review November 29, 2023 21:01
@TimothyMakkison
Copy link
Collaborator Author

Can you elaborate on the bug? Probably run dotnet clean; dotnet build. Note: we recently switched to the simplified .NET 8.0 artifacts output: #917

Thanks dotnet clean; dotnet build fixed it for me. I've lost the error but it looks like Verify was trying to call a file for the wrong .NET version.

I'd add a sentence in derived-type-mapping.md that derived type mappings are also supported for existing target object mappings with a reference to the existing target object mapping page.

👍

@TimothyMakkison
Copy link
Collaborator Author

TimothyMakkison commented Nov 30, 2023

Looks like the benchmark check is failing. Can't run a benchmark right now, but I don't think this PR should have a massive impact on performance.

@latonz
Copy link
Contributor

latonz commented Dec 2, 2023

@TimothyMakkison not sure what we should do about the benchmark test, it's failing quite often recently without any notable performance issues.

@TimothyMakkison
Copy link
Collaborator Author

Strange 🤷 perhaps github pipelines are running slow? For now we could change the threshold percentage

@latonz
Copy link
Contributor

latonz commented Dec 2, 2023

@TimothyMakkison created #969 to increase the threshold.

@TimothyMakkison TimothyMakkison force-pushed the existing_map_derive branch 3 times, most recently from 0aec783 to da6c1ff Compare December 4, 2023 14:27
latonz
latonz previously approved these changes Dec 4, 2023
@TimothyMakkison
Copy link
Collaborator Author

TimothyMakkison commented Dec 4, 2023

Thanks for the fixing the benchamark, no clue why the integration failed.

Hopefully that's the end of the CI issues 🤞 although code coverage is being weird.

@latonz
Copy link
Contributor

latonz commented Dec 6, 2023

@TimothyMakkison codecov has been super unreliable lately, I think some other open source projects replaced it recently. I created #930 a few days ago to look for alternatives and probably switch to another coverage provider or remove it completely. If you know a good solution, please add a comment there 😊

@latonz latonz enabled auto-merge (squash) December 6, 2023 09:20
@latonz latonz merged commit 918f59d into riok:main Dec 6, 2023
17 checks passed
Copy link

github-actions bot commented Dec 6, 2023

🎉 This PR is included in version 3.3.0-next.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MapDerivedType attribute can't map to a existing target
2 participants