处理2个编译器错误,将C#转换为F#

Mai*_*ein 2 c# f#

将此代码移植到f#时遇到一些问题

public class MyForm : Form
{
    public MyForm ()
    {
        Text = "My Cross-Platform App";
        Size = new Size (200, 200);
        Content = new Label { Text = "Hello World!" };
    }

    [STAThread]
    static void Main () {
        var app = new Application();
        app.Initialized += delegate {
            app.MainForm = new MyForm ();
            app.MainForm.Show ();
        };
        app.Run ();
    }
}
Run Code Online (Sandbox Code Playgroud)
open System
open Eto.Forms
open Eto.Drawing

type MyWindow()=
    inherit Form()
    override this.Size = Size(500,500)
    override this.Text = "test" // no abstract property was found
    override this.Content = new Label() // no abstract property was found

[<STAThread>]
[<EntryPoint>]
let main argv = 
    let app = new Application()
    app.Initialized.Add( fun e -> app.MainForm <- new Form()
                                  app.MainForm.Show())
    app.Run()
    0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud)

我有一些问题:

1.)如何从基类访问成员?

{
    Text = "My Cross-Platform App";
    Size = new Size (200, 200);
    Content = new Label { Text = "Hello World!" };
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用覆盖,但它只适用于大小而不适用于内容和文本.

2.)如何将此行转换为f# Content = new Label { Text = "Hello World!" };

Joh*_*mer 6

快速修复

type MyWindow()=
    inherit Form()
    override this.Size = Size(500,500)
    override this.Text = "test" // no abstract property was found
    override this.Content = new Label() // no abstract property was found
Run Code Online (Sandbox Code Playgroud)

应该

type MyWindow() as this =
    inherit Form()
    do this.Size <- Size(500,500)
    do this.Text <- "test" 
    do this.Content <- new Label() 
Run Code Online (Sandbox Code Playgroud)

最后,

Content = new Label { Text = "Hello World!" }
Run Code Online (Sandbox Code Playgroud)

let Content = new Label(Text = "Hello World!")
Run Code Online (Sandbox Code Playgroud)