Overriding a method from a C # class in F # makes a method uninteresting?

I have the following C # classes:

public class Foo {
    protected virtual void Bar (){
    }
}

public class Baz : Foo {
    protected override void Bar (){
    }
}

If I am interested in them, there is always a panel of methods:

[<EntryPoint>]
let main args =
    let methodFromFoo = typedefof<Foo>.GetMethod("Bar", BindingFlags.Instance ||| BindingFlags.NonPublic)
    if (methodFromFoo <> null) then
        Console.WriteLine ("methodFromFoo is not null")
    else
        Console.WriteLine ("methodFromFoo is null")

    let methodFromBaz = typedefof<Baz>.GetMethod("Bar", BindingFlags.Instance ||| BindingFlags.NonPublic)
    if (methodFromBaz <> null) then
        Console.WriteLine ("methodFromBaz is not null")
    else
        Console.WriteLine ("methodFromBaz is null")

The result of this is is not nullfor both cases.

However, when I do the same with the F # class, the result is different:

type FSharpBaz() =
    inherit Foo()
    override this.Bar () =
        Console.WriteLine ("yeh")

[<EntryPoint>]
let main args =
    let methodFromFsharp = typedefof<FSharpBaz>.GetMethod("Bar", BindingFlags.Instance ||| BindingFlags.NonPublic)
    if (methodFromFsharp <> null) then
        Console.WriteLine ("methodFromFsharp is not null")
    else
        Console.WriteLine ("methodFromFsharp is null")

But why??? Can I get the method through reflection if my class is created using F #? I am devastated.

+4
source share
1 answer

, , , FSharpBaz.Bar public, protected. , ildasm. 8.5.3.2 CLI

, , , , .

, F # public ,

, , , ()

+8

All Articles