feat: support unmanaged generic type constraint#334
Conversation
There was a problem hiding this comment.
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
unmanagedconstraint (must come before other constraints) - Added test coverage for
unmanagedconstraint 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 |
🚀 Benchmark ResultsDetails
|
|
|
This is addressed in release v0.46.0. |



This PR adds support for the
unmanagedgeneric type constraint in Mockolate's code generation. Theunmanagedconstraint 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:
unmanagedconstraint (must come before other constraints)unmanagedconstraint scenarios