Fix ObservableAsProperty InitialValue being ignored for empty strings - #484
Open
ChrisPulman with Copilot wants to merge 2 commits into
Open
Fix ObservableAsProperty InitialValue being ignored for empty strings#484ChrisPulman with Copilot wants to merge 2 commits into
ChrisPulman with Copilot wants to merge 2 commits into
Conversation
…fields Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix backing field initialization for ObservableAsProperty on empty string
Fix ObservableAsProperty InitialValue being ignored for empty strings
Aug 16, 2026
ChrisPulman
approved these changes
Aug 17, 2026
ChrisPulman
marked this pull request as ready for review
August 17, 2026 06:13
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #484 +/- ##
=======================================
Coverage 95.30% 95.30%
=======================================
Files 78 78
Lines 5047 5051 +4
Branches 625 628 +3
=======================================
+ Hits 4810 4814 +4
Misses 115 115
Partials 122 122 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
glennawatson
approved these changes
Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[ObservableAsProperty(InitialValue = "")]on a non-nullablestringproduced an uninitialized backing field, becauseGetInitialValueSyntaxdiscarded any value that was null, empty, or whitespace before checking the property type.Changes
ObservableAsPropertyGenerator{FromObservable}.Execute.cs— the string-type check now runs before the empty check. For string properties any suppliedInitialValue(including empty/whitespace) is emitted as a quoted literal; non-string types keep the previous behaviour of skipping empty/whitespace values, since= ;is not valid C#.InitialValueis supplied, a non-nullablestringbacking field is now initialized tostring.Emptyrather than left null. This addresses the second half of the issue ("should initialization to empty string occur automatically?") and the CS8618 reported in [Bug]: [ObservableAsProperty] on partial property not initializing backing field? #370, which is raised at the user-authored constructor and therefore not silenced by the generated file's#pragma warning disable.string?and all other types are unchanged.InitialValuecase (covering bothstringandstring?); three existing OAPH snapshots updated for the new default.ReactiveUI.SourceGenerators.Execute— added aPLCStatuspartial property usingInitialValue = ""so the scenario is exercised at compile time.string.Emptydefault.Two review comments were raised and assessed as non-issues: the
##stringsuffix match cannot produce false positives (the partial-property marker always ends in##), and the missing blank line between generated members is a pre-existing template quirk present in snapshots before this change.