2010-12-29 12 views
5

मैं एफ # में निम्नलिखित सी # इंटरफ़ेस को लागू करना चाहते हैं:एफ # में सी # इंटरफेस को कैसे कार्यान्वित करें?

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); 
} 

यह मैं क्या कोशिश की है, लेकिन यह मुझे देता है: "पर या अभिव्यक्ति में इस बिंदु से पहले अधूरा संरचित निर्माण"

#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 

मैं क्या गलत कर रहा हूँ? शायद इंडेंटेशन गलत है?

+6

कोष्ठक शायद सिर्फ लापता एफ # के साथ Mono.Addins उपयोग करने के लिए का एक उदाहरण है? –

+1

सी # इंटरफ़ेस क्या है? आपने सी # में एक सीएलआर इंटरफ़ेस परिभाषित किया है। –

उत्तर

3

मैंने टिप्पणियों में @ मार्क का जवाब सत्यापित किया।

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); 
    } 

} 

निम्नलिखित एफ # कार्यान्वयन (केवल परिवर्तन वस्तु निर्माण पर () जोड़ रहा है) काम करता है "ठीक": निम्नलिखित सी # कोड को देखते हुए

#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() 

आप अब #light उपयोग करने के लिए की जरूरत नहीं है हालांकि (यह डिफ़ॉल्ट है) और आप NamespaceDictionary पैरामीटर नाम चेतावनी का नेतृत्व करना चाह सकते हैं कि "अपरकेस वेरिएबल पहचानकर्ताओं को आम तौर पर पैटर्न में उपयोग नहीं किया जाना चाहिए, और मिस्पेल्ट पैटर्न नाम इंगित कर सकते हैं।" यह भी ध्यान रखें कि आप (भ्रमित करने के लिए सवाल नहीं के लिए कहा है, लेकिन आसान सी # से आ रही द्वारा) लागू सदस्यों तक पहुँचने के लिए ISparqlCommand को MyClass कास्ट करने के लिए की आवश्यकता होगी: उदाहरण के (MyClass() :> ISparqlCommand).Name

1

हर किसी के लिए धन्यवाद! निम्नलिखित कोड वास्तव में काम करता है:

namespace MyNamespace 

open System 
open System.Collections.Generic; 
open Mono.Addins 

[<assembly:Addin>] 
    do() 
[<assembly:AddinDependency("TextEditor", "1.0")>] 
    do() 

[<Extension>] 
type MyClass() = 
    interface ISparqlCommand with 
     member this.Name 
      with get() = 
       "Finding the path between two tops in a Graph" 
     member this.Run(NamespacesDictionary, repository, argsRest) = 
      new System.Object() 

यह भी कैसे `नई System.Object()` पर

संबंधित मुद्दे