F # Public override of protected methods

I just started learning F # and I use it in Monogame to create a simple game to help me learn the various functions of the language. I ended up in a roadblock trying to access my game class from the outside, because the Monogame Game class defines methods as protected. Attempting to override the method publicly causes an error saying that setting accessibility modifiers is not allowed.


Base class defined in C #

public class Base
{
    protected virtual void Method()
    {
        //...
    }
}

Open override in F #

type Game as game = 
    inherit Base()

    //Error: Accessibility modifiers are not permitted on overrides or interface implementations
    override public game.Method = 
        //...
        ()

Q: What is the correct way to publicly override the F # inherited C # protected method?


+4
source share
1 answer

F #, #. @Endjru's, - , ;

type Game as game = 
    inherit Base()

    override game.Method = 
        //...
        ()

    member game.PublicMethod = game.Method
+2

Source: https://habr.com/ru/post/1547543/


All Articles