必须在上面定义F# - 类型

时间:2018-02-21 18:11:20

标签: .net f#

我有F#个文件,其中定义了MyUIImagePickerControllerDelegateNewListing类型:

[<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内的MyUIImagePickerControllerDelegateMyUIImagePickerControllerDelegate内的NewListing。由于F#要求文件中稍后使用的所有类型都被定义在使用它们的位置之上,因此该代码将无法工作......如何解决此问题?

1 个答案:

答案 0 :(得分:3)

递归类型:

type Foo = ...

and Bar = ...

所以

[<Register ("MyUIImagePickerControllerDelegate")>]
type MyUIImagePickerControllerDelegate() as x = ...

and [<Register ("NewListing")>]
    NewListing (handle:IntPtr) as this = ...