Stumped with a OOP interface F# question.
Example – when I create a class and try to implement a single method Run(string,string,string) from a Namespace Example from an Interface IRunner
I can see in .NET Reflector what really gets created is a private method named Example-IRunner-Run(string,string,string) If I then want to expose this back to a C# lib it presents an issue. Via reflection – code I’m not in control of is just looking for a class with a public Run method. How do I solve? Can’t seem to find any documentation on this.
Problem 1 – Run should be public some how ends up private
Problem 2 – the crazy long method name – instead of just Run
Not sure if I need to be using some modifier keywords or a signature file…. just not just where to start with the (1) private and (2) the strange method name (reflection won’t find)
note: in this example Run returns an int
In this current implementation I’m just trying to return a 1 to “proof of concept” that I can do this simple thing in F#
example code:
namespace MyRunnerLib
open Example
type MyRunner() = class
interface IRunner with
member this.Run(s1, s2, s3) = 1
end
Additionally, there are a few options how to write this. Robert’s version has the actual implementation in the additional member. If you place the implementation into the interface, you can avoid the casting.
(Also note that you don’t need
class..endkeywords):Slightly clearer way is to define the functionality as a local function and then just export it two times: