Conversation
Property path expressions may contain conversions. Reference casts and boxing conversions leave the chain target usable as-is, but numeric and user-defined conversions produce a different value, and the next step in the path must read from that converted value. Compile a conversion invoker for value-changing conversions so subsequent property access targets the converted result, and keep the pass-through for reference casts and boxing. Fixes #1177
|
P2: Converted property paths collide in the property-factory cache. Locations:
Reproduced with both expressions on the same model: the expected initial scales were Suggested fix: build factory identity from the complete expression path, including each member's identity, conversion source/destination types, any user-defined conversion method, and the result type. |
Problem
Property path expressions passed to
WhenPropertyChanged/WhenValueChangedmay contain conversions.ExpressionBuilder.CreateInvokertreated everyExpressionType.Convertnode as a no-op pass-through, returning the original chain target unchanged.That is correct for reference casts and boxing/unboxing, where the target object is the same instance and the runtime resolves the cast anyway. It is wrong for value-changing conversions: numeric conversions (
(decimal)price.Amount) and user-defined conversion operators produce a different value, and the next step in the property path must read from that converted value rather than from the original operand.The result was that an expression such as
price => ((decimal)price.Amount).Scaleattempted to readdecimal.Scaleoff the sourcedouble, surfacing an error instead of the observed value.Fix
CreateInvokernow distinguishes the two cases:Conversions are also supported as the final step of a path, and reference/interface casts continue to follow object replacement in nested chains.
Tests
Adds
WhenPropertyChangedBehaviorFixture.Conversions.cscovering:notifyOnInitialValueThe shared fixture gains a seeded
Randomizer(deterministic, seed written to test output) and a smallObservablePricemodel to support these tests. Prior focused validation of these conversion tests passed.Docs
Public XML documentation on
WhenPropertyChanged/WhenValueChangedand the cache/list instruction files now state that property paths evaluate numeric conversions before subsequent property access.Scope
Conversion handling only. No changes to property-subscription initialization lifetime behavior.
Fixes #1177