A Software Engineering Blog

by Nick Holmes

  Home  |   Contact  |   Syndication    |   Login
  11 Posts | 0 Stories | 6 Comments | 0 Trackbacks

News

Archives

Post Categories

I tidied up the F# web service, mainly by factoring out an interface for the web service. Without the attributes it looks like this:

type ITestWebService =
    abstract TestMethod: Param:string -> string
type TestWebService() =
    interface ITestWebService with
        member x.TestMethod s = "Hello " + s;

However, I noticed when I was setting up the C# host, I needed to cast to get to access the interface, like this:

TestWebService tws = new TestWebService();
ITestWebService itws = tws as ITestWebService;

Neither of these far more obvious ways to access the member work:

tws.TestMethod("test");                     // Doesn't compile
tws.ITestWebService.TestMethod("test");     // Doesn't compile

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Tuesday, May 05, 2009 12:44 PM

Feedback

# re: Accessing F# Interface Implementations from C# 5/10/2009 10:21 AM Richard
F# only has explicit interface implementation, to expose the interface member directly in the implementing type you need a second implementation (and presumably will forward from one to the other).

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: