-
Notifications
You must be signed in to change notification settings - Fork 2
Only Collection/Dictionary check Count/Length Property when Serialize. (string does not check Length any more.)
#147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added a condition to return the null check directly for members of type string. This ensures correct null check logic for string properties in generated code.
Updated the logic to check for Count and Length properties only if the member is a collection or dictionary type. This prevents unnecessary property checks on non-collection types and improves type safety.
There was a problem hiding this 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 pull request refines the serialization check logic to distinguish between collection/dictionary types and other types (specifically strings). The key change restricts the Count and Length property checks to only apply to actual collection and dictionary types, preventing strings from being treated as collections even though they have a Length property.
Key changes:
- Modified
GetCheckIfNotEmptyto add type checking before Count/Length validation - String types now only check for null, not for empty length
- Collection and dictionary types continue to check both null and Count/Length > 0
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changed the default value of StringField in CsPackage to '123' and made StringBuilderField nullable. Updated IntergrationTests to remove the empty string from StringArrayFields initialization.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #147 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 99 99
Lines 2186 2186
Branches 231 231
=======================================
Hits 2151 2151
Misses 23 23
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This pull request updates the logic in the
GetCheckIfNotEmptymethod to more accurately check for non-empty collections and dictionaries when generating code. Now, for collection or dictionary types, the method ensures not only that the property is not null but also that it contains at least one element.Improvements to collection and dictionary checks:
GetCheckIfNotEmptyinLightProtoGenerator.csto add an extra check for.Count > 0or.Length > 0when the member is a collection or dictionary type, ensuring the property is both non-null and non-empty. [1] [2]