Domanda

Ho guardato dappertutto così e internet ma non riesce a capire cosa mi manca e come implementare l'interfaccia ilist generica in F # per questo tipo:

type OrCondition() as self =
    inherit Condition()
    member val Conditions: List<Condition> = new List<Condition>() with get, set
    interface IList<Condition> with
        member this.Item 
            with get(index) = self.Conditions.[index]
            and  set(index)(value) = self.Conditions.[index] <- value
        member this.IndexOf item = self.Conditions.IndexOf(item)
        member this.Insert(index, item) = self.Conditions.Insert(index, item)
        member this.RemoveAt(index) = self.Conditions.RemoveAt(index)
        member this.Count with get() = self.Conditions.Count
        member this.IsReadOnly with get() = false
        member this.Add(item) = self.Conditions.Add(item)
        member this.Clear() = self.Conditions.Clear()
        member this.Contains(item) = self.Conditions.Contains(item)
        member this.CopyTo(conditions, index) = self.Conditions.CopyTo(conditions, index)
        member this.Remove(item) = self.Conditions.Remove(item)
        member this.GetEnumerator() = (Seq.cast<Condition> self.Conditions).GetEnumerator()
.

In questo momento il compilatore si lamenta di non aver implementato le raccolte .Incutibile .Incolabile.getenumerator () e lo so, ma davvero non so come farlo.

Aggiornamento: Risultato finale di seguito.Grande grazie al signor Garland.Inoltre, vale la pena di sottolineare che ho fatto riferimento solo sistema.Collections.Generic e dimenticato di un sistema di riferimento.Collezione quando la versione non generica di Ienumerable Geside.Così triste resharper non supporta F #.

open System.Collections
open System.Collections.Generic

type OrCondition() as self =
    inherit Condition()
    member val Conditions = new List<Condition>() with get, set
    interface IList<Condition> with
        member this.Item 
            with get(index) = self.Conditions.[index]
            and  set(index)(value) = self.Conditions.[index] <- value
        member this.IndexOf item = self.Conditions.IndexOf(item)
        member this.Insert(index, item) = self.Conditions.Insert(index, item)
        member this.RemoveAt(index) = self.Conditions.RemoveAt(index)
        member this.Count with get() = self.Conditions.Count
        member this.IsReadOnly with get() = false
        member this.Add(item) = self.Conditions.Add(item)
        member this.Clear() = self.Conditions.Clear()
        member this.Contains(item) = self.Conditions.Contains(item)
        member this.CopyTo(conditions, index) = self.Conditions.CopyTo(conditions, index)
        member this.Remove(item) = self.Conditions.Remove(item)
        member this.GetEnumerator() = self.Conditions.GetEnumerator() :> IEnumerator<Condition>
        member this.GetEnumerator() = self.Conditions.GetEnumerator() :> IEnumerator 
.

È stato utile?

Soluzione

Questo perché IList dispone di due metodi GetEnumerator, uno per l'interfaccia IEnumerable<T> e una per l'interfaccia IEnumerable non generica.

Puoi aggiungere questo utente per implementare IEnumerable

member this.GetEnumerator() = (this.Conditions :> IEnumerable).GetEnumerator()
.

Altri suggerimenti

Il modo più semplice è

interface System.Collections.IEnumerable with
    member this.GetEnumerator() = this.Conditions.GetEnumerator() :> _
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top