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.
source
share