Skip to content

feat: support unmanaged generic type constraint#334

Merged
vbreuss merged 2 commits intomainfrom
topic/support-unmanaged-generic-type-constraint
Dec 22, 2025
Merged

feat: support unmanaged generic type constraint#334
vbreuss merged 2 commits intomainfrom
topic/support-unmanaged-generic-type-constraint

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Dec 22, 2025

This PR adds support for the unmanaged generic type constraint in Mockolate's code generation. The unmanaged constraint is a special type constraint in C# that requires a type to be an unmanaged type (value type with no reference-type fields).

Key changes:

  • Updated generic constraint handling to properly position unmanaged constraint (must come before other constraints)
  • Added test coverage for unmanaged constraint scenarios
  • Refactored code to remove unused properties from Type entity and improve event handling code

@vbreuss vbreuss self-assigned this Dec 22, 2025
Copilot AI review requested due to automatic review settings December 22, 2025 14:38
@vbreuss vbreuss added the enhancement New feature or request label Dec 22, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the unmanaged generic type constraint in Mockolate's code generation. The unmanaged constraint is a special type constraint in C# that requires a type to be an unmanaged type (value type with no reference-type fields).

Key changes:

  • Updated generic constraint handling to properly position unmanaged constraint (must come before other constraints)
  • Added test coverage for unmanaged constraint scenarios
  • Refactored code to remove unused properties from Type entity and improve event handling code

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Source/Mockolate.SourceGenerators/Entities/GenericParameter.cs Reordered constraint generation logic to emit unmanaged first, fixing constraint ordering rules
Source/Mockolate.SourceGenerators/Entities/Type.cs Removed unused properties (IsArray, IsTypeParameter, ElementType) and ToString override
Source/Mockolate.SourceGenerators/Entities/Class.cs Refactored event filtering to use clearer tuple syntax and removed unused void type mapping
Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.ImplementClassTests.cs Added test cases for unmanaged and other constraint combinations
Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.DelegateTests.cs Added test for Span/ReadOnlySpan delegate parameters
Tests/Mockolate.SourceGenerators.Tests/GeneralTests.cs Added comprehensive test for various generic type parameters and updated attribute test fixture

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
[Host] : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.462 μs 0.0073 μs 0.0064 μs 0.2232 - 3.66 KB
Simple_Moq 180.994 μs 1.5414 μs 1.4418 μs 0.4883 - 14.77 KB
Simple_NSubstitute 5.635 μs 0.0158 μs 0.0148 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.174 μs 0.0235 μs 0.0220 μs 0.4959 - 8.11 KB

@vbreuss vbreuss enabled auto-merge (squash) December 22, 2025 14:45
@sonarqubecloud
Copy link

@github-actions
Copy link

Test Results

    14 files  ± 0      14 suites  ±0   6m 1s ⏱️ +31s
 1 791 tests + 5   1 790 ✅ + 5  1 💤 ±0  0 ❌ ±0 
11 966 runs  +15  11 965 ✅ +15  1 💤 ±0  0 ❌ ±0 

Results for commit 54c0aca. ± Comparison against base commit d6d691f.

@vbreuss vbreuss merged commit 5069c06 into main Dec 22, 2025
12 checks passed
@vbreuss vbreuss deleted the topic/support-unmanaged-generic-type-constraint branch December 22, 2025 14:46
@github-actions
Copy link

This is addressed in release v0.46.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants