我如何将以下 C# 代码翻译成 F#:

public class AnimalCell : UICollectionViewCell
{
[Export ("initWithFrame:")]
  public AnimalCell (RectangleF frame) : base (frame) {}
}

我尝试按照以下链接中的示例进行操作,但是,我不知道接下来如何进行:
Overriding Constructors in F#

到目前为止,我想出的是:
[<Register ("AnimalCell")>]
type AnimalCell (handle: IntPtr) as this =
    inherit UICollectionViewCell (handle)

我将在哪里添加 Export 以及参数?我知道我应该使用 new() 但我不确定如何继续。

最佳答案

像这样的事情会让你开始:
F# UICollectionViewCell 子类

[<Register ("AnimalCell")>]
type AnimalCell =
    inherit UICollectionViewCell

    [<DefaultValue>] static val mutable private id : NSString
    static member init =
        printfn "Initializing AnimalCell."
        AnimalCell.id <- new NSString("animalCell")

    [<Export("init")>]
    new() = { inherit UICollectionViewCell() } then AnimalCell.init
    [<Export("initWithFrame:")>]
    new(frame: CGRect) = { inherit UICollectionViewCell(frame) } then AnimalCell.init
    [<Export("initWithCoder:")>]
    new(coder: NSCoder) = { inherit UICollectionViewCell(coder) } then AnimalCell.init

    new(handle: IntPtr) = { inherit UICollectionViewCell(handle) } then AnimalCell.init

    override this.ReuseIdentifier = AnimalCell.id

关于c# - UICollectionViewCell 定义 F#,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48038906/

10-12 14:11