fix(generator): improve UsePublicModifier option parsing for boolean values #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Pull Request
📋 Summary
This PR refactors the
UsePublicModifieroption handling in the source generator to improve type safety and correctly handle empty/null boolean MSBuild properties. The change addresses an issue wherebool.Parse()would throw an exception when the MSBuild property was not explicitly set (null/empty string).Key Changes:
UsePublicModifierfrombooltostring?inCompilationOptions(src/LayeredCraft.SourceGeneratorTools.Generator/CompilationOptions.cs:6)bool.Parse()withbool.TryParse()to safely handle null/empty values (src/LayeredCraft.SourceGeneratorTools.Generator/SourceGeneratorToolsGenerator.cs:45-46)✅ Checklist
🧪 Related Issues or PRs
This addresses an edge case where MSBuild properties may not be set, which would cause the generator to fail with a parsing exception.
💬 Notes for Reviewers
The main improvement here is defensive programming - using
bool.TryParse()instead ofbool.Parse()ensures the generator handles missing or empty MSBuild properties gracefully. The default behavior (when the property is not set or invalid) is nowfalse, which matches the original intent ofbool.Parse(usePublic ?? "false").The new test case
Initialize_EmptyOptions_GeneratesOutputverifies that the generator can handle empty configuration values without throwing exceptions.