我有F#
个文件,其中定义了MyUIImagePickerControllerDelegate
和NewListing
类型:
[<Register ("MyUIImagePickerControllerDelegate")>]
type MyUIImagePickerControllerDelegate() as x =
inherit UIImagePickerControllerDelegate ()
let mutable parentView : UIViewController = null
member this.GetSelectedImage
with get() = selectedImage
and set(value) = selectedImage <- value
member this.GetParentView
with get() = parentView
and set(value) = (
parentView <- value
)
override x.FinishedPickingImage(controller : UIImagePickerController, image : UIImage, dict : NSDictionary) =
let chosenImage = image
(parentView :?> NewListing).GetIm1.Image <- chosenImage
parentView.DismissModalViewController(true)
[<Register ("NewListing")>]
type NewListing (handle:IntPtr) as this =
inherit UIViewController (handle)
override x.ViewDidLoad () =
base.ViewDidLoad ()
let del = new MyUIImagePickerControllerDelegate()
del.GetParentView <- x
问题在于这两行:
(parentView :?> NewListing).GetIm1.Image <- chosenImage
和:
let del = new MyUIImagePickerControllerDelegate()
正如您所见,我正在使用NewListing
内的MyUIImagePickerControllerDelegate
和MyUIImagePickerControllerDelegate
内的NewListing
。由于F#
要求文件中稍后使用的所有类型都被定义在使用它们的位置之上,因此该代码将无法工作......如何解决此问题?
答案 0 :(得分:3)
递归类型:
type Foo = ...
and Bar = ...
所以
[<Register ("MyUIImagePickerControllerDelegate")>]
type MyUIImagePickerControllerDelegate() as x = ...
and [<Register ("NewListing")>]
NewListing (handle:IntPtr) as this = ...