Fix builder generation for nullable dictionary and nullable value type properties - #114
Conversation
Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
|
@copilot it's partially wrong, we don't need this nonnullableTypeFullname. |
…ableTypeFullName Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
Refactored to use the nullable strategy approach. Removed Commit: 6518f17 |
|
@copilot ok, you can revert back to the previous solution but make sure the value types works correctly still (for example |
…tc.) Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
Reverted to NonNullableTypeFullName solution with fix for nullable value types. Updated the implementation to:
Added test for Commit: 8ffbe25 |
pmrogala
left a comment
There was a problem hiding this comment.
Use this NonNullableTypeFullName only for situations when there is new {TypeFullName}() situations. The nullable can be a generic parameter of a Nullbox (I think that's true, you can prove me otherwise :) )
…generic parameters Co-authored-by: pmrogala <9459432+pmrogala@users.noreply.github.com>
Correct! Updated to use Commit: 8346b4a |
Generator fails with CS8628 when models contain nullable dictionary properties (
Dictionary<K,V>?,IDictionary<K,V>?,IReadOnlyDictionary<K,V>?).Root cause: Generator incorrectly attempted to use nullable type syntax in
new T()expressions, which is invalid in C#.Changes:
NonNullableTypeFullNameproperty that intelligently handles nullable types:string?,Dictionary<K,V>?): Strips the?annotation for use innewinstantiationsint?,DateTime?): Strips to underlying type (e.g.,int?→int) fornewinstantiationsTypeFullName(preserves?) sinceNullBox<Dictionary<K,V>?>andNullBox<int?>are validNonNullableTypeFullName(strips?) sincenew Dictionary<K,V>?()andnew int?()are invalidThis fix correctly handles the distinction between where nullable types are allowed (as generic type parameters) versus where they're prohibited (in
newexpressions), ensuring correct behavior for both reference types (dictionaries, strings, etc.) and value types (int?, DateTime?, etc.).Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.