Reflection / C # errors when publishing an F # class that implements an interface

I have an interface written in C #, but when implementing it in F # I noticed some oddities.

  • The F # class must be passed to the interface before C # can use it
  • After casting, WPF cannot read its properties (Bindings failed and SNOOP could not reflect it)
  • I can wrap the object in C # code and everything works fine.

interface

public interface IInterpret {
  public string Name {get;}
  public IEnumberable<Project> Interpret(string text);
}

Class F #

type Interpreter()=
  interface IInterpret with
    member x.Name = "FParsec Based"
    member x.Interpret(str) = Seq.empty

The code below cannot compile. The error is that Interpreter does not implement IInterpert.

public ViewModel(){
  IInterpret i = new FSharpLib.Interperter(); 
}

This is my current solution.

public class MyProxy: IInterpret{
    private IInterpret _cover;

    public MyProxy()        {
        _cover = new FSharpLib.Interperter() as IInterpret;
    }
    public string Name { get { return _cover.Name; } }
    public IEnumerable<Project> Interpret(string text){
        return _cover.Interpret(text);
    }
}

Is there something I'm doing wrong with my F # class class or is a proxy required? I am using current VS2010 f # and not out of range.

+2
source share
1 answer

F # . , .

WPF , ,

http://leecampbell.blogspot.com/2008/09/generic-binding-in-wpf-through-explicit.html

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/92a2a3ba-74a6-4c79-9c75-f42d232a4dbf

? ( Bing-ing "wpf ".)

( , -

type Interpreter()= 
    member x.Name = "FParsec Based" 
    member x.Interpret(str:string) = Seq.empty 
    interface IInterpret with 
        member x.Name = x.Name
        member x.Interpret(str) = x.Interpret(str)

" ", .)

+2

All Articles