在 ReactiveUI 5.2.0 和 F# 3.1 中,以下 F# 代码在构造对象时会导致 InvalidOperationException(来自 C# WPF 应用程序)
消息是“对象或值的初始化导致对象或值在完全初始化之前被递归访问”,它发生在读取传递到的属性期间ObservableForProperty
(尽管默认是跳过初始值)。
type MyVM() as this =
inherit ReactiveObject()
let source : obj = obj()
let ofp =
this.ObservableForProperty([|"Source"|])
.Select(fun x -> x.Value)
.ToProperty(this, (fun y -> y.Result), obj()) // Exception when executing this
member this.Result with get() = ofp.Value
member this.Source with get() = source // Exception here "The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized"
编辑添加:
问题似乎ToProperty
是导致ObservableForProperty
在订阅时查询“源”属性,并且 F# 在查询属性之前检查构造函数是否已完成。
更多信息:
在中,和ReactiveNotifyPropertyChangedMixin.nestedObservedChanges
的组合导致在通过通知任何更改之前查询值kicker
fillInValue
PropertyChanged