Skip to content

feat(response): remove class constraints to support value types#43

Merged
davidkallesen merged 1 commit into
mainfrom
hotfix/class-restrictions
Mar 24, 2026
Merged

feat(response): remove class constraints to support value types#43
davidkallesen merged 1 commit into
mainfrom
hotfix/class-restrictions

Conversation

@davidkallesen

Copy link
Copy Markdown
Collaborator

Summary

The EndpointResponse generic types and helper methods (InvalidContentAccessException, CastContent) had where T : class
constraints that prevented generated client code from using value types like Guid, int, or DateTime as response content types. This
caused CS0452 compilation errors in projects using the source generator when an API returns a value type. This PR removes all
unnecessary class constraints across the response type hierarchy and builder interfaces.

Changes

💥 Breaking Changes

  • Remove where TSuccess : class constraint from EndpointResponse
  • Remove where TSuccess : class and where TError : class constraints from EndpointResponse<TSuccess, TError>
  • Remove class constraints from IMessageResponseBuilder.BuildResponseAsync generic methods
  • Remove class constraints from MessageResponseBuilder.BuildResponseAsync generic methods

🐛 Fixes

  • Remove where TExpected : class from InvalidContentAccessException — only uses typeof(TExpected).Name, no reference
    type needed
  • Update CastContent to use is pattern matching instead of as operator, enabling value type unboxing

✨ Features

  • EndpointResponse and EndpointResponse<TSuccess, TError> now accept value types (Guid, int, bool, DateTime, etc.)

📝 Documentation

  • Update README to reflect removed class constraints on IMessageResponseBuilder method signatures

✅ Tests

  • Add value type test coverage: InvalidContentAccessException, EndpointResponse success/failure/wrong-type scenarios

Notes

This is a source-compatible relaxation of constraints — all existing code using reference types continues to work unchanged. For
value type TSuccess, SuccessContent returns default(TSuccess) (e.g., Guid.Empty) on failure rather than null, since unconstrained
T? is a nullable annotation only and does not produce Nullable for value types.

@davidkallesen davidkallesen force-pushed the hotfix/class-restrictions branch from e380f8b to 8e6c480 Compare March 24, 2026 13:57
@davidkallesen davidkallesen merged commit 284f61f into main Mar 24, 2026
4 checks passed
@davidkallesen davidkallesen deleted the hotfix/class-restrictions branch March 24, 2026 14:04
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.

1 participant