Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dameng324
Copy link
Owner

This pull request updates the logic in the GetCheckIfNotEmpty method 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:

  • Enhanced GetCheckIfNotEmpty in LightProtoGenerator.cs to add an extra check for .Count > 0 or .Length > 0 when the member is a collection or dictionary type, ensuring the property is both non-null and non-empty. [1] [2]

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.
Copilot AI review requested due to automatic review settings January 8, 2026 14:35
Copy link
Contributor

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 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 GetCheckIfNotEmpty to 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
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.39%. Comparing base (b1b2b37) to head (baf9eaf).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jan 8, 2026


BenchmarkDotNet v0.15.3, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.67GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
  [Host]    : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.11 (9.0.11, 9.0.1125.51716), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Deserialize_ProtoBuf_net .NET 10.0 .NET 10.0 775.5 μs 2.25 μs 1.88 μs 1.24 562 KB 0.88
Deserialize_GoogleProtoBuf .NET 10.0 .NET 10.0 615.2 μs 1.36 μs 1.13 μs 0.98 648.7 KB 1.01
Deserialize_LightProto .NET 10.0 .NET 10.0 625.6 μs 3.72 μs 2.90 μs 1.00 639.98 KB 1.00
Deserialize_ProtoBuf_net .NET 8.0 .NET 8.0 910.0 μs 2.85 μs 2.38 μs 1.46 562 KB 0.88
Deserialize_GoogleProtoBuf .NET 8.0 .NET 8.0 828.7 μs 2.98 μs 2.49 μs 1.33 648.7 KB 1.01
Deserialize_LightProto .NET 8.0 .NET 8.0 622.4 μs 2.74 μs 2.14 μs 1.00 639.98 KB 1.00
Deserialize_ProtoBuf_net .NET 9.0 .NET 9.0 845.5 μs 5.76 μs 5.11 μs 1.36 562 KB 0.88
Deserialize_GoogleProtoBuf .NET 9.0 .NET 9.0 712.1 μs 3.87 μs 3.62 μs 1.14 648.7 KB 1.01
Deserialize_LightProto .NET 9.0 .NET 9.0 622.8 μs 1.17 μs 1.03 μs 1.00 639.98 KB 1.00

BenchmarkDotNet v0.15.3, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.67GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
  [Host]    : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.11 (9.0.11, 9.0.1125.51716), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Serialize_ProtoBuf_net .NET 10.0 .NET 10.0 928.9 μs 2.51 μs 2.22 μs 1.33 526.41 KB 1.03
Serialize_GoogleProtoBuf .NET 10.0 .NET 10.0 787.2 μs 2.71 μs 2.26 μs 1.13 512.95 KB 1.00
Serialize_LightProto .NET 10.0 .NET 10.0 697.9 μs 1.99 μs 1.77 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 8.0 .NET 8.0 1,059.1 μs 6.09 μs 5.09 μs 1.38 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 8.0 .NET 8.0 837.6 μs 4.25 μs 3.76 μs 1.09 512.95 KB 1.00
Serialize_LightProto .NET 8.0 .NET 8.0 768.6 μs 3.97 μs 3.32 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 9.0 .NET 9.0 978.2 μs 3.37 μs 2.82 μs 1.29 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 9.0 .NET 9.0 817.2 μs 5.38 μs 4.77 μs 1.07 512.95 KB 1.00
Serialize_LightProto .NET 9.0 .NET 9.0 760.3 μs 2.73 μs 2.42 μs 1.00 512.92 KB 1.00

@dameng324 dameng324 merged commit f6ee2ff into main Jan 8, 2026
8 checks passed
@dameng324 dameng324 deleted the skip-string-field-only-when-it-is-null branch January 8, 2026 15:02
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.

2 participants