Ant*_*eev 7 .net c# inheritance f#
我想在F#中实现以下C#接口:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Addins;
[TypeExtensionPoint]
public interface ISparqlCommand
{
string Name { get; }
object Run(Dictionary<string, string> NamespacesDictionary, org.openrdf.repository.Repository repository, params object[] argsRest);
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的,但它给了我:"表达式中或之前的不完整的结构化构造"
#light
module Module1
open System
open System.Collections.Generic;
type MyClass() =
interface ISparqlCommand with
member this.Name =
"Finding the path between two tops in the Graph"
member this.Run(NamespacesDictionary, repository, argsRest) =
new System.Object
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?也许压痕是错的?
我在评论中验证了@Mark的回答.给出以下C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace org.openrdf.repository {
public class Repository {
}
}
namespace CSLib
{
[System.AttributeUsage(System.AttributeTargets.Interface)]
public class TypeExtensionPoint : System.Attribute
{
public TypeExtensionPoint()
{
}
}
[TypeExtensionPoint]
public interface ISparqlCommand
{
string Name { get; }
object Run(Dictionary<string, string> NamespacesDictionary, org.openrdf.repository.Repository repository, params object[] argsRest);
}
}
Run Code Online (Sandbox Code Playgroud)
以下F#实现(仅()
在对象构造中添加更改)工作"很好":
#light
module Module1
open System
open System.Collections.Generic;
open CSLib
type MyClass() =
interface ISparqlCommand with
member this.Name =
"Finding the path between two tops in the Graph"
member this.Run(NamespacesDictionary, repository, argsRest) =
new System.Object()
Run Code Online (Sandbox Code Playgroud)
虽然您不再需要使用#light
(这是默认设置),但您可能希望引用NamespaceDictionary
参数名称警告"大写变量标识符通常不应在模式中使用,并且可能指示拼写错误的模式名称." 另请注意,您需要强制MyClass
转换ISparqlCommand
才能访问已实现的成员(不是您提出的问题,但很容易因来自C#而感到困惑):例如(MyClass() :> ISparqlCommand).Name