Skip to content

#305 Introduce generic polymorphic type-mapping attributes - #316

Merged
sanelli merged 1 commit into
mainfrom
305-introduce-generic-polymorphic-type-mapping-attributes-no-behaviour-change-just-handier-to-use-for-developers
Aug 8, 2026
Merged

#305 Introduce generic polymorphic type-mapping attributes#316
sanelli merged 1 commit into
mainfrom
305-introduce-generic-polymorphic-type-mapping-attributes-no-behaviour-change-just-handier-to-use-for-developers

Conversation

@sanelli

@sanelli sanelli commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add sealed generic helpers MappaTypeMappingAttribute<TTarget, TSource> and MappaTypeMappingDefaultAttribute<TDefault> (MapSourceType) that derive from the existing attributes; non-generic APIs remain.
  • Teach AttributeDataExtensions to parse the generic attribute forms and reconstruct the same non-generic models.
  • Cover with Mappa.Tests / Generator.Tests (including duplicated polymorphism integration tests), update samples and docs, bump to 10.2.0-alpha.58.

Test plan

  • .\Scripts\RunTestsAndReportCoverage.ps1 — line/branch/method greater than or equal to pre-change baseline
  • Confirm [MappaTypeMapping<TTarget, TSource>] generates the same switch mapping as the typeof form
  • Confirm [MappaTypeMappingDefault<TDefault>] matches MapSourceType with an explicit target type
  • Samples PolymorphismMapper / PolymorphismMapperWithMapDefaultWithExplicitType compile and pass sample tests

Add MappaTypeMappingAttribute<TTarget, TSource> and MappaTypeMappingDefaultAttribute<TDefault> as sealed wrappers over the existing attributes, teach the generator to parse them, and cover with unit/integration tests, samples, and docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Code coverage

Compared against the latest published coverage history from the code coverage gist.

Metric Baseline PR Δ Trend
Line 98.3% 98.3% 0 =
Branch 90.4% 90.4% 0 =
Method 100% 100% 0 =

No coverage metric dropped by more than 1 percentage point(s) versus baseline.

Benchmarks

Winners (chart subset)

Benchmark Best time Best memory
Array To List Mapperly (-0.5%) Mapperly, Mappa
List To Array Mappa Mapperly, Mappa
Fast List To Array Mapperly (-10%) Mapperly, Mappa
Dictionary Mapperly (-21.2%) Mapperly (-32%)
Objects mapping Mapperly (-4%) Mapperly (-5.4%)
IQueryable Projection Mapster (-1.3%) Mapster (-2.8%)
String To Enum Mappa n/a
Enum To String Mapperly (-31%) n/a
Reference Reusing Mappa Automapper (-17.3%)

AutoMapper is the BenchmarkDotNet ratio baseline. Absolute values are mean time in nanoseconds and allocated bytes. Ratio columns are competitor / Mappa as a percentage (n/a when either side is missing or Mappa is zero).

Benchmark Automapper Mean (ns) Automapper Allocated (B) Mapster Mean (ns) Mapster Allocated (B) Mapperly Mean (ns) Mapperly Allocated (B) Mappa Mean (ns) Mappa Allocated (B) Automapper/Mappa Time Automapper/Mappa Alloc Mapperly/Mappa Time Mapperly/Mappa Alloc Mapster/Mappa Time Mapster/Mappa Alloc
ArrayToListBenchmark 377360 592056.32 322160 648058.88 24770 128051.2 24900 128051.2 1515.5% 462.4% 99.5% 100% 1293.8% 506.1%
DictionaryBenchmark 386270 615014.4 362850 742277.12 37450 151019.52 47500 222218.24 813.2% 276.8% 78.8% 68% 763.9% 334%
EnumToStringBenchmark 66.236 24 20.749 24 0.501 0 0.726 0 9123.4% n/a 69% n/a 2858% n/a
FastListToArrayBenchmark 372000 592025.6 314680 648028.16 24780 128020.48 27530 128020.48 1351.3% 462.4% 90% 100% 1143% 506.2%
IQueryableProjectionBenchmark 640700 68034.56 628900 67266.56 633400 69201.92 637400 69201.92 100.5% 98.3% 99.4% 100% 98.7% 97.2%
ListToArrayBenchmark 372380 592025.6 318850 648028.16 24930 128020.48 24900 128020.48 1495.5% 462.4% 100.1% 100% 1280.5% 506.2%
NestedDtoBenchmark 417660 742809.6 389370 789555.2 39900 149401.6 41570 157900.8 1004.7% 470.4% 96% 94.6% 936.7% 500%
ReferenceReusingSharedDagBenchmark 333.7 344 200.4 400 304.9 800 110.6 416 301.7% 82.7% 275.7% 192.3% 181.2% 96.2%
StringToEnumBenchmark 57.633 0 91.088 216 3.547 0 3.544 0 1626.2% n/a 100.1% n/a 2570.2% n/a

@sanelli
sanelli merged commit 19da61c into main Aug 8, 2026
1 check passed
@sanelli
sanelli deleted the 305-introduce-generic-polymorphic-type-mapping-attributes-no-behaviour-change-just-handier-to-use-for-developers branch August 8, 2026 17:26
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.

Introduce generic polymorphic Type Mapping attributes: no behaviour change, just handier to use for developers

1 participant