Using a nullable decimal as a variable, [Reactive] public decimal? CustomPrice { get; set; }
, I am trying to update it with the following:
this.WhenAnyValue(x => x.DiscountPercent, x => x.DiscountFlat, x=>x.UnitPriceOriginal,
(percent, flat, orig) => ((percent > 0) || (flat > 0)) ? orig * percent - flat : (decimal?)null)
.ToPropertyEx(this, x => x.CustomPrice);
DiscountPercent DiscountFlat UnitPriceOriginal
are all decimal variables. DiscountPercent DiscountFlat
are set from the database or from user input fields. CustomPrice
is editable from a user input field as well, which has been working to update CustomPrice
. CustomPrice
is then used to set the decimal value UnitPrice
using:
this.WhenAnyValue(x => x.CustomPrice, x => x.UnitPriceOriginal,
(custom, orig) => custom ?? orig)
.ToPropertyEx(this, x => x.UnitPrice);
I need the CustomPrice
to be updated when values are entered into DiscountPercent
and/or DiscountFlat
otherwise it needs to be null
which then sets the UnitPrice
to the UnitPriceOriginal
. With the first block of code I get a runtime error:
System.ArgumentException: 'Object of type ObservableAsPropertyHelper`1[System.Nullable`1[System.Decimal]]' cannot be converted to type 'System.Nullable`1[System.Decimal]'.'
I have tried many different ways to work around this, but when updating a nullable variable I run into errors. Is there a different way I can set a nullable decimal as an Observable during runtime? Is there something I am missing?